Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created July 4, 2011 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zolomon/1063934 to your computer and use it in GitHub Desktop.
Save Zolomon/1063934 to your computer and use it in GitHub Desktop.
Python exercises Task 3 (Chapter 3 & 4)
#!/usr/local/bin/python3.2
def computepay(hours, rate):
if hours < 1: raise ValueError("No hours")
if rate < 1.0: raise ValueError("No rate")
if hours > 40:
return (40 * rate) + ((hours - 40) * rate * 1.5)
else:
return hours * rate
try:
hours = int(input("Enter Hours: "))
rate = float(input("Enter Rate: "))
print(computepay(hours, rate))
except ValueError as ex:
print("Please enter only numbers:", ex)
#!/usr/local/bin/python3.2
def computegrade(score):
if score > 1 or score < 0: return "Bad score"
if score >= 0.9:
return"A"
elif score >= 0.8:
return"B"
elif score >= 0.7:
return "C"
elif score >= 0.6:
return "D"
elif score < 0.6:
return "F"
try:
score = float(input("Enter score: "))
print(computegrade(score))
except ValueError as ex:
print("Bad score")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment