#Exercise 3.1 """ use try and except with gross_pay function to calc ot""" hours = raw_input("Please Enter Hours Worked Here: ") print "" pay = raw_input("Please Enter Your Pay Rate Here: ") print "" float_hours = float(hours) float_pay = float(pay) print float_hours print float_pay if float_hours > 40.0: ot_hours = float_hours - 40.0 ot_pay = ot_hours * (float_pay * 1.5) gross_pay = ot_pay + (40.0 * float_pay) print gross_pay else: gross_pay = float_hours * float_pay print gross_pay #Exercise 3.2 """write a script that uses try/except to handle errors""" hours = raw_input("Please Enter Hours Worked Here: ") print "" pay = raw_input("Please Enter Your Pay Rate Here: ") print "" try: float_hours = float(hours) except: print "please use numeric input" try: float_pay = float(pay) except: print "please use numeric input" print float_hours print float_pay if float_hours > 40.0: ot_hours = float_hours - 40.0 ot_pay = ot_hours * (float_pay * 1.5) gross_pay = ot_pay + (40.0 * float_pay) print gross_pay else: gross_pay = float_hours * float_pay print gross_pay #exercise 3.3 """write a script that prompts 0.0 and 1.0 a >= 0.9 b >= 0.8 c >= 0.7 d >= 0.6 f < 0.6 """ grade_in = raw_input("Please enter your grade: ") try: float_grade_in = float(grade_in) except: print "Please use a number between 0.0 and 1.0" print float_grade_in print "" if float_grade_in >= 0.9: print "The grade is an A" elif float_grade_in < 0.9 and float_grade_in >= 0.8: print "The grade is an B" elif float_grade_in >= 0.7 and float_grade_in < 0.8: print "The grade is an C" elif float_grade_in >= 0.6 and float_grade_in < 0.7: print "The grade is an D" else: print "The grade is an F"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question