In [ ]:
def isOdd():
print "This function will print a 0 if your number is even and a 1 if your number is odd."
print "Note: this program does not handle 0's properly."
check = input("What number would you like to check? :")
output = check%2
print output
isOdd()
In [ ]:
## Convert2.py
def temps():
celsius = input("What is the Celsius temperature? ")
fahrenheit = 9.0 / 5.0 * celsius + 32
print "Temperature is", fahrenheit, "degrees fahrenheit."
if fahrenheit >= 90:
print "It's really hot out there, be careful!"
if fahrenheit <= 30:
print "Brrrrr. Be sure to dress warmly"
temps()
In [ ]:
## is odd, v2.0
def isOdd():
print "This function will print a 0 if your number is even and a 1 if your number is odd."
print "Note: this program does not handle 0's properly."
check = input("What number would you like to check?: ")
output = check%2
if output == 1:
print "Your number is odd."
else:
print "Your number is even."
isOdd()
In [ ]:
## isOdd, v3.0
def isOdd():
print "This function will tell you if your number is even or if it is odd."
print "It will handle 0 differently."
check = input("What number would you like to check?: ")
output = check%2
if check == 0:
print "Your number is zero."
elif output == 1:
print "Your number is odd"
else:
print "Your number is even."
isOdd()
In [ ]:
## isOdd, v 4.0
## This version handles exceptions
def isOdd():
print "This function will print a 0 if your number is even and a 1 if your number is odd."
try:
check = input("What number would you like to check?: ")
output = check%2
if check == 0:
print "Your number is zero."
elif output == 1:
print "Your number is odd"
else:
print "Your number is even."
except NameError:
print "You must enter a number, not a word. Try again!"
isOdd()
In [ ]:
##eligible v1.0
def eligible():
job = raw_input("Would you like to me a member of the Senate or the House?: ")
job = job.lower()
age = input("How old are you?: ")
citizen = input("How many years have you been a citizen of the United States?: ")
if job == "senate":
if age >= 30:
if citizen >= 9:
print "You are eligible to be a Senator!"\
"If for some reason you want to be a Senator."
else:
print"You are ineligible to be a Senator -"
"you must be citizen for 9 years."
else:
print "You can't be Senator - you are too young."\
elif job == "house":
if age >= 25:
if citizen >= 7:
print "You are eligible to be a member of the House! " \
"Although why you would want to be is anyone's guess."
else:
print "You are ineligible to be a member of the House -"
"You must be a citizen for 7 years."
else:
print "You are ineligible to be a member of the House - "\
"You are too young. I know, they act like chidren, but they"
" are technically all over the age of 25."
else:
print "That's not a job - try again!"
eligible()