# This is code which would help you to start programming with python! # Lines which start with # are COMMENTARY: everything typed after # the first hash sign is ignored until the end of the line. print("Hi!") # you can put your commentary after code too! #----------------------------------------------------------------------------- # We should start with a few important concepts: # 1. VALUES: the simplest types of values are numbers and strings. # Numbers can be integers or floating point numbers. # The distinction is often very important so bear it in mind. print("We are going to print some numbers now") print(4) # an integer print(5.01) # a floating point number # You can use the usual mathematical operations with numbers: # What type of number will be results of these operations? print(4+10) print(4-10) print(4.-10) print(4*10) print(4.0*10) print(4/10) print(4.26*(-17.83)) # Strings are simply bits of text contained between quotation marks: print("\nWe are going to print some strings now") # \n adds new line print('Hello, world!') print("Hello, world!") # Take care to be consistent! You should open and close with # the same quotation marks! # You can concatenate strings using '+' sign: print("alpha") print("alpha"+"beta") print("alpha"+" "+"beta") # 2. EXPRESSIONS: a sequence of operations, functions and value which can be # evaluated ("solved") to have a value of its own. All arithmetic examples from above # are expressions. A single value can be thought of as an expression too! # As you might have notice, print() only prints the value (i.e. solution) of # your expression. Compare: print("\nLet's look at some expressions and their values") print("Expression: (12+18)*10") print((12+18)*10) print("Expression: 200+20*5") print(200+20*5) #--------------------------------------------------------------------- # 3. VARIABLES: a variable can be thought of as a box with a label # (the name of the variable) into which you can put a value. # You assign the value to a variable using the '=' sign: a = 3 # To the left of the equal sign is the name of the variable, # to the right - the value it has from now on. # Whenever you use the variable's name, # its value will be substituted, for example: print("print variable a: ") print(a) b = 5 print("print the sum of variables a and b: ") print(a+b) print("print the mixed expression of variables and simple values: ") print(13-a+b*4) # The name of a variable should start with a letter or an underscore, #and you can use letters, numbers and underscore. Upper and lower case matter! my_variable = 3 My_variable = 5 MyVariable = 10 print("This variables are different:") print(my_variable, My_variable, MyVariable) # If you are using an expression in the right part of the assignment operator, # the VALUE of the expression will be used: c = 13-a+b*4 print("What value does c hold now? Let's have a look") print(c) # you can change the value of the variable: a = 100 print("print variable a: ") print(a) a = "Ha-ha, I'm not a number anymore!" print("print variable a: ") print(a) # 3. print() and input(): # As you have already seen, print() prints the VALUE of whatever # is in the brackets. # input() waits for you to type something, and then passes it on as a STRING. # You need to assign that value to a variable otherwise it will disappear! print("\nNow you type something!") input() # nothing happened! Whatever you've typed is there no more. print("Now type something again!") a = input() # the line of text you've typed is now stored in the variable a print("Let's see... Variable a now has the value: ") print(a) # You are now ready to write simple Q&A programs! # try helloworld.py and questions.py