# Add access to the math library import math # Example of removing hardcoding literals NUM_INPUTS = 3 # Example of using math library math.sqrt(25) # simple if statement if ( True ): print("this string") print("this one too") # showing that if the statement is false, it doesn't run the code block if ( False ): # bad formatting #print( "some text" ) #print ( "more text") print("some text") print("more text") # bad coding style (bad variable names) s = "James Brown" t = "Andrew Case" # good variable names student = "James Brown" teacher = "Andrew Case" # use consistent variable names student_id = "N12345678" teacher_name = "Andrew Case" # be consistent with _'s or Caps teacherName = "Evan Korth" # Avoid hardcoding values: #average = total/MAX_INPUTS # bad coding style; uses hardcoded values # we only have 3 grades #average = total/3 # Examples of if/elif/else statements is_even = True user_input = input("Give me a number: ") number = int(user_input) if ( number == 1 ): print("I like one just fine") if ( number < 2 ): print("I like small numbers too") if ( number == 1 or number == 2 ): print("I like small numbers too") if ( number == 13 ): print("You guessed the magic number!") print("1 is fine") print("2 is alright") print("3 is great") print("But the best number is 13") elif ( number == 2 ): # else if print("2 is alright too!") elif ( number == 3 ): print("3 is a great number!") elif ( True ): print("This is a tautology") else: print("That's a stupid number!") print("Maybe you should guess something else!") if (True): print("true is true") else: print("true is not true") # Same thing as above if (1 == 1): print("This statement is true") else: print("This statement is false") if (False): print("false is true") else: print("false is not true") # same as above if (1 != 1): print("This statement is true") else: print("This statement is false") # These if statements are all equivalent #if (0 < number < 10): #if ((0 < number) and (number < 10)): if (0 < number and number < 10): print("between 0 and 10") else: print("number is not between zero and 10")