''' Purpose: demonstrate arithmetic and use of variables for naming things ''' # name some values a = 13 b = 5 # We have variable identifiers and assign them values (a is the variable # and 13 is the value!) so the computer sets aside memory to associate # a to 13. # Again notes will be posted so no need for rapid typing.. # I can use commas to print multiple things in a print statement! # So it will print the string in the double/single quotes and then # whatever is after the comma and each thing separated by a comma # is separated by a space. print( "a =", a ) print( "b =", b ) input() # input() is waiting for user input! The user has to type something # and hit enter before the program executes the next lines. # display some integer calculations print( 'Integer arithmetic' ) total = a + b difference = a - b product = a * b dec_quotient = a / b # Decimal division can yield a decimal! int_quotient = a // b # Integer division will chop off everything after the whole number (chop off decimal) remainder = a % b # So when it comes to remainder, think remainder # after a division. 3%2 is 1 because there is # a remainder of 1 when 3 is divided by 2. power = a ** b # If you want to print more than one thing, separate them by commas! # You can do this with different *types* more on this later so hang tight. # Notice how we printed a string with a variable so it printed # the string with the variable value. # print() - everything inside the parenthesis is printed! # Anything in double quotes is printed exactly as it says since # it's a string. VARIABLES when printed print the value. # print( 'a =', a) will print the string 'a =' with a space and the # value of a which is 13. Console will say a = 13 print( a, "+", b, "=", total ) # Remember that if you wanna print a value print the variable/identifier. print( 'a + b =', total ) print( 'total =', total ) print( 'a - b =', difference ) print( 'a * b =', product ) print( 'a / b =', dec_quotient ) print( 'a // b =', int_quotient ) print( 'a % b =', remainder ) print( 'a ** b =', power ) input() # introduce some other built-in functions print( 'Some handy functions' ) c = -10 d = 1.75 e = -1.75 print( "c =", c ) print( "d =", d ) print( "e =", e ) input() # Important!! print(), abs(), float(), int() are built in functions! # abs() gives back absolute value of whatever you pass into it. # float() converts whatever you pass into it into a decimal number! # A float is a decimal number. # An int is an integer number. # int() converts whatever you pass into it into an integer number. # int chops off the decimal portion which is why 1.75 became 1 :) abs_c = abs( c ) float_c = float( c ) int_d = int( d ) print( 'abs( c ) =', abs_c ) print( 'float( c ) =', float_c ) print( 'int( d ) =', int_d ) print()