fork download
  1. """
  2. Day 1 - Intro
  3.  
  4. What we're doing this time
  5. 1. Comments
  6. 2. Variables
  7. 3. Intro to operators
  8. 4. First program
  9. """
  10.  
  11. # === Comments: begin every program with comments
  12.  
  13. # Single line comments: all text following a # sign (hash sign) is ignored.
  14. # It's good practice to have as many comments in your script as possible.
  15. # This help you remember why you wrote something in a specific way.
  16. ## Alt-3 (add) Alt-4 (remove)
  17.  
  18. """
  19. Multi-line comments: all text between triple double-quotes is ignored.
  20. """
  21.  
  22. # === Variables
  23.  
  24. # We can store values for things (numbers, names, true and false) in what are
  25. # called "variables". Variable names should be meaningful, and are case sensitive (Num is not num)​
  26. # the first character must be a letter or an underscore​, and CANNOT be a digit
  27. # can contain both letters, digits, and underscores​
  28. # cannot be a Python keywords: sum, if, for, and, or, not, def, class, True, False
  29. # VALID variaable names:
  30. ##my_variable
  31. ##userAge
  32. ##total_sum_2024
  33. ##_temp_value
  34. ##MAX_LIMIT
  35.  
  36. # === Standard functions
  37.  
  38. # We can have the Python Shell display what is stored inside the variable using the
  39. # function "print".
  40. greeting = "Hello World"
  41. print(greeting) # the value in greeting will be displayed
  42.  
  43. # We can have the Python Shell display what the data type of the value inside the variable is
  44. # using the function "type" inside the "print" function.
  45. print(type(greeting)) # the data type of someName will be displayed
  46.  
  47. # === Operators
  48.  
  49. # Python utilizes the following symbols to represent different operations:
  50. ## = represents asignment
  51. ##(the variable is on the left of the equal sign and the value being assigned is on the right)
  52. num1 = 15 # the integer value 15 will be stored as num1
  53. print(num1)
  54.  
  55. ## + represents summation or concatenation:
  56. thisSum = 5 + 10 # the value 15 will be stored
  57. print(thisSum)
  58.  
  59. thisConcat = "hello, " + "students!" # "hello, students!" will be stored
  60. print(thisConcat)
  61.  
  62. ## - represents subtraction
  63. thisSubtraction = 9 - 2 # the value 7 will be stored
  64. print(thisSubtraction)
  65.  
  66. ## * represents multiplication
  67. thisMult = 56 * 3 # the value 168 will be stored
  68. print(thisMult)
  69.  
  70. ## ** represents exponentiation
  71. thisExp = 3**5 # the value 243 will be stored
  72. print(thisExp)
  73.  
  74. ## / represents floor division
  75. thisDiv = 8/2 # the value 4 will be stored
  76. print(thisDiv)
  77.  
  78. ## // represents floor (integer) division
  79. ##(It divides the first number by another and rounds down the result to the nearest whole number)
  80. thisFloorDiv = 9//2 # the value stored will be 4
  81. print(thisFloorDiv)
  82.  
  83. ## % represents the modulo operation
  84. ##(It returns the remainder after one number is divided by another)
  85. thisMod = 5%2 # the value 1 will be stored
  86. print(thisMod)
  87.  
  88. # === Example
  89.  
  90. # open the file you downloaded to your CS1315 folder named 01code.py.
  91. # Use this standard script format to begin coding your solutions in the default function "main".
  92. # Begin the file with documentation with the file name, your name, and the problem description.
  93. """ FILE NAME: *.py
  94. STUDENT:
  95. DESCRIPTION:
  96. """
  97. # Next use the following basic main function template.
  98. def main():
  99. """ function documentation: input, output, purpose """
  100. pass
  101.  
  102. if __name__ == '__main__':
  103. main()
  104.  
  105.  
  106.  
  107.  
Success #stdin #stdout 0.03s 9704KB
stdin
Standard input is empty
stdout
Hello World
<class 'str'>
15
15
hello, students!
7
168
243
4.0
4
1