Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # first lecture, Data Analytics with Python
- # Python basics + NumPy
- print("Spyder says hello!")
- salary = 3000
- raised = 1.20
- salary = salary * raised
- person = "John Doe"
- snowing = True
- number = "123"
- number_int = int(number)
- print(salary)
- print(person)
- print(snowing)
- apples = 75
- people = 8
- # / for traditional division, // for leaving out the decimals
- apples_for_people = apples // people
- # remainder / modulus is the same as C, %
- leftovers = apples % people
- value = 100
- value += 50
- print(value)
- # easiest way to make string in Python, is to use f-strings
- first_name = "John"
- surname = "Doe"
- greetings = f"Hello, my name is {first_name} {surname}"
- print(greetings)
- year = 2021
- text = f"This year is {year}. Previous year was {year - 1}."
- print(text)
- # A NEW FILE
- print("If-statements")
- number = input("Give a number: ")
- number = int(number)
- total = number + 62
- print(number)
- if number > 0:
- print("Number is greater than zero.")
- elif number < 0:
- print("Number is less than zero.")
- else:
- print("Number is zero.")
- print("This is an else statement.")
- print("We are now outside the if/elif/else structure")
- # in C-language, it's something like this
- #if(number > 0)
- #{
- # print("Number is greater than zero.");
- #}
- # NEW FILE
- grades = [1, 5, 3, 4, 3, 2]
- # second grade, note: indexing starts from 0
- print(grades[1])
- # first grade
- print(grades[0])
- # last grade in this list
- print(grades[5])
- # this one doesn't exist
- # print(grades[6])
- # you can change list values by using the index
- grades[0] = 3
- weekdays = ("Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday", "Sunday")
- # tuple can't be altered without creating the tuple again from scratch
- # weekdays[0] = "Funday"
- # a list sum and print example
- shopcart = [99, 49, 299, 149]
- total_price = sum(shopcart)
- print(f"Total price of your purchase: {total_price} €")
- # you can also create lists from user input strings
- # original string
- #numbers = "5 12 33 45 6"
- numbers = input("Give some numbers, separate by space: ")
- # split to string list
- number_list = numbers.split()
- # convert string list to int list
- number_list = list(map(int, number_list))
- # NEW FILE
- day_1 = [-22, -20, -17, -15, -10]
- day_2 = [-10, -8, -12, -7, -6]
- day_3 = [-32, -28, -29, -27, -30]
- temperatures = [day_1, day_2, day_3]
- # simple loops
- numbers = [55, 44, 22, 33, 11, 66]
- for x in range(11):
- print(x)
- for x in range(1, 11):
- print(x)
- for year in range(2000, 2022):
- print(year)
- for n in numbers:
- print(n)
- # in C-language, it's something like this
- #for(int a = 0; a <= 10; a++)
- #{
- # print(a)
- #}
- # you can use if -statements in loops too
- for x in range(1, 11):
- if x % 2 == 0:
- print(x)
- # if you have a list of lists, you usually need to do this (two loops):
- for day in temperatures:
- for t in day:
- print(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement