Advertisement
tuomasvaltanen

Untitled

Sep 5th, 2024
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. print("Hello world!")
  2.  
  3. print("Press Ctrl + Shift + F10 to run the code (shortcut)")
  4. print("Press Cmd + Shift + R on MacOS instead")
  5.  
  6. # NEW FILE
  7. print("Testing!")
  8.  
  9. # remember to also print a variable if you want to see the result
  10. # variables do nothing in code by themselves, unless they are used somehow
  11. age = 27
  12. print(age)
  13.  
  14. salary = 3200
  15. print(salary)
  16.  
  17. name = "Test Person"
  18. print(name)
  19.  
  20. tax = 1.24
  21. print(tax)
  22.  
  23. # NEW FILE
  24.  
  25. # traditionally you have to convert numbers to text
  26. # before combining them into a bigger text
  27. age = 27
  28. age_text = str(age)
  29. print("Your age is: " + age_text)
  30.  
  31. # BETTER WAY today, use the f-string
  32. # f-string converts any data type differences
  33. # automatically into a single text
  34. number = 123
  35. print(f"Your number: {number}")
  36.  
  37. # NEW FILE
  38.  
  39. # summing up values
  40. total = 176 + 287
  41. print(total)
  42.  
  43. # substraction example
  44. difference = 1856 - 917
  45. print(difference)
  46.  
  47. # increase salary by +20%
  48. salary = 2650
  49. salary = salary * 1.2
  50. print(salary)
  51.  
  52. # typicla division
  53. wind_speed = 25 / 3.6
  54. print(wind_speed)
  55.  
  56. # by using //, we can divide and
  57. # leave out the decimals from the end result
  58. apples = 25 // 4
  59. print(apples)
  60.  
  61. # because 6 * 4 = 24, 1 is the leftover
  62. # % is the complement of //
  63. # % is called the modulo -operator
  64. # basically, in this case, "what is left if we divide 25 by 4?"
  65. leftover = 25 % 4
  66. print(leftover)
  67.  
  68. # NEW FILE
  69.  
  70. # typically we use variables to combine them into some
  71. # calculation formula
  72. salary = 3100
  73. savings = 1850
  74. debt = 400
  75.  
  76. # calculate all money together based on the variables
  77. # print out result with f-string
  78. total_money = salary + savings - debt
  79. print(f"Total money: {total_money} €")
  80.  
  81. # NEW FILE
  82.  
  83. # this is a typical structure in most of the
  84. # exercises in this course
  85.  
  86. # PHASE 1:
  87. # Ask all needed variables from the user (input)
  88. # You can have more than one variable as well
  89.  
  90. # remember, user input from the user
  91. # is always in text format first
  92. # even if user gave you a number
  93. number1 = input("Give a number: ")
  94.  
  95. # if you need decimals too, use float(number1) instead
  96. number1 = int(number1)
  97.  
  98. # PHASE 2: do the needed calculations
  99. # try summing up now
  100. number2 = 234
  101. total = number1 + number2
  102.  
  103. # PHASE 3: Print out the result
  104. # for the user in the required format
  105. print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement