Created
July 4, 2011 20:57
-
-
Save Zolomon/1063934 to your computer and use it in GitHub Desktop.
Python exercises Task 3 (Chapter 3 & 4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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