Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Hello world!")
- print("Press Ctrl + Shift + F10 to run the code (shortcut)")
- print("Press Cmd + Shift + R on MacOS instead")
- # NEW FILE
- print("Testing!")
- # remember to also print a variable if you want to see the result
- # variables do nothing in code by themselves, unless they are used somehow
- age = 27
- print(age)
- salary = 3200
- print(salary)
- name = "Test Person"
- print(name)
- tax = 1.24
- print(tax)
- # NEW FILE
- # traditionally you have to convert numbers to text
- # before combining them into a bigger text
- age = 27
- age_text = str(age)
- print("Your age is: " + age_text)
- # BETTER WAY today, use the f-string
- # f-string converts any data type differences
- # automatically into a single text
- number = 123
- print(f"Your number: {number}")
- # NEW FILE
- # summing up values
- total = 176 + 287
- print(total)
- # substraction example
- difference = 1856 - 917
- print(difference)
- # increase salary by +20%
- salary = 2650
- salary = salary * 1.2
- print(salary)
- # typicla division
- wind_speed = 25 / 3.6
- print(wind_speed)
- # by using //, we can divide and
- # leave out the decimals from the end result
- apples = 25 // 4
- print(apples)
- # because 6 * 4 = 24, 1 is the leftover
- # % is the complement of //
- # % is called the modulo -operator
- # basically, in this case, "what is left if we divide 25 by 4?"
- leftover = 25 % 4
- print(leftover)
- # NEW FILE
- # typically we use variables to combine them into some
- # calculation formula
- salary = 3100
- savings = 1850
- debt = 400
- # calculate all money together based on the variables
- # print out result with f-string
- total_money = salary + savings - debt
- print(f"Total money: {total_money} €")
- # NEW FILE
- # this is a typical structure in most of the
- # exercises in this course
- # PHASE 1:
- # Ask all needed variables from the user (input)
- # You can have more than one variable as well
- # remember, user input from the user
- # is always in text format first
- # even if user gave you a number
- number1 = input("Give a number: ")
- # if you need decimals too, use float(number1) instead
- number1 = int(number1)
- # PHASE 2: do the needed calculations
- # try summing up now
- number2 = 234
- total = number1 + number2
- # PHASE 3: Print out the result
- # for the user in the required format
- print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement