''' Purpose: demonstrate arithmetic and use of variables for naming things ''' # Introduction to variables for naming values! # Format is: # variable = value # # name some values a = 13 b = 5 print( "a =", a ) print( "b =", b ) # Since we assigned the value 13 to a, when we print a, it prints the value # stored in the variable! # We can use variables to reference specific values we stored in those variables. input() # input() is a function that wants user input! It's waiting for # the user to give it some input (keyboard) and when you hit enter, # it registers that input. # display some integer calculations print( 'Integer arithmetic' ) # Notice how our variables/identifiers are on the left and the values are on # the right. # The = assigns values on the right to the identifier/name on the left! total = a + b difference = a - b product = a * b dec_quotient = a / b int_quotient = a // b remainder = a % b # This one gives you the remainder after doing a/b power = a ** b # Remember our variables stored the values so get rid of total and # we're not printing that value anymore. print( 'a + b =', total ) # Addition print( 'a - b =', difference ) # Subtraction print( 'a * b =', product ) # Multiplication print( 'a / b =', dec_quotient ) # DECIMAL DIVISION print( 'a // b =', int_quotient ) # INTEGER DIVISION (chops off decimals) print( 'a % b =', remainder ) # MODULUS (remainder operator) - JUST REMAINDER print( 'a ** b =', power ) # EXPONENTIATION # Pls learn the % one!!! (ex 5%2 is remainder of 5/2 # so the result is 2 remainder 1 so it gives 5%2 = 1! # a%b gives you the remainder of a/b # 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() # abs( x ), float( x ) , and int( x ) are built in functions abs_c = abs( c ) # gives you absolute value of whatever is passed into it float_c = float( c ) # converts a number to a float (decimal) int_d = int( d ) # converts a number to an integer # Run these to see how they work! # int(3.5) would be 3 (chops off decimals NOT ROUND) # int(1.9999999) is 1! (just chops off decimals) # int literally just gives you whatever is before the decimal point # SNAKE CASE # If you want a variable with multiple words or something # then use underlines to separate words # do_this = 1 # dontdothispls = 1 # Both work one's just ugly # Try: # a = 2 # print(a) # a = 3 # print(a) print( 'abs( c ) =', abs_c ) print( 'float( c ) =', float_c ) print( 'int( d ) =', int_d ) print()