''' Purpose: relate a cautionary tale -- make sure your expressions do what they are supposed to do ''' # get Celsius temperature c reply = input( 'Enter Celsius temperature: ' ) c = int( reply ) # Convert string of user input to integer and store the number in variable c print( ) # compute respectively, f1 and f2, the decimal and integer Fahrenheit equivalents of c # Formula for Fahrenheit is 9/5 c + 32 where c is the Celcius temperature # How would we express this in Python? # Integer vs. Float Division # 9/5 = 1.8 # 9//5 = 1 (Integer division is where the decimal gets chopped off) # How you order operators / numbers matters in your calculations! # When Python does calculations, it follows order of operations! (PEMDAS) # PEMDAS - Operator Precedence follows order of operations in Python # PEMDAS - Parentheses Exponentiation Multiplication Division Addition Subtraction # Order of operations goes left first ^ to right down the line f1 = ( ( 9/5 ) *c ) + 32 f2 = ( ( 9//5 ) * c ) + 32 # Wrong! 1 * c + 32 (will yield wrong result mathematically) f2 = ( 9 * c // 5 ) + 32 f2 = 32 + ( 9 * c // 5 ) # Python will first do 9 * c (M) and then do result of 9*c // 5 (D) and then 32 + that result 9*c // 5 (A) # display results print( c, 'C =', f1, 'F' ) print( ) print( c, 'C =', f2, 'F' )