#!/usr/bin/env python # coding: utf-8 # In[11]: # Section 3.1 - if statements # idea: control flow by asking a yes or no question and # doing "stuff" if the answer is "yes" and not doing "stuff" # if the answer is "no" # # Syntax in Python # if condition: # stuff # more stuff # more more stuff # # we will see later an example # # How do we specify a condition? # # Relational operators # Operator Meaning # > greater than # < less than # >= greater than or equal to # <= less than or equal to # == (mathematically) equal <-- note "variable assignment" # is a different concept # from "equals" # != not (mathematically) equal # # # Expression Meaning # x < y "Is x less than y?" # x > y "Is x greater than y?" # x<=y "Is x less than or equal to y?" # x>=y "Is x greater than or equal to y?" # x==y "Is x equal (mathematically) to y?" # x!=y "Is x NOT equal (mathematically) to y?" # # Test this out x=1 y=0 print("x>y is",x>y) print("x85% encouragement and if htey had # an average score of <60% tell them they need to do better. # # Make the cutoff scores as named constant LOW_AVG=60 HIGH_AVG=85 # Ask the user for three test scores: # cant forget to typecast as float score1=float(input("What is the score on the first exam?")) score2=float(input("What is the score on the second exam?")) score3=float(input("What is the score on the third exam?")) # compute the average average=(score1+score2+score3)/3 # implement the decision structures print("Your average test score is",average) # question: how do we tell it to throw out impossible scores? if average>100: print("I think you made a mistake in inputting your grades.") if average>HIGH_AVG: print("Great job! Keep it up!") if averageOVERTIME_CUTOFF): overtimehours=hours-OVERTIME_CUTOFF totalpay=OVERTIME_CUTOFF*payrate+OVERTIME_MULTIPLIER*overtimehours*payrate else: totalpay=hours*payrate print("You earned \$",totalpay,".",sep='')