Started learning Python today. Will post shitty programs as evidence of progress.
calculator.py
loop = 1
choice = 0
print "Welcome to MY calculator! Version dumb.butt"
while loop == 1:
print""
print "What would you like to do?"
print " "
print "1 - add two numbers"
print "2 - subtract two numbers"
print "3 - multiply two numbers"
print "4 - divide two numbers"
print "5 - exponent two numbers"
print "6 - quit Rob's calculator"
print " "
choice = input("Select your Choice:")
if choice == 1:
add1 = input("first number: ")
add2 =input("second number: ")
sum = add1 + add2
print "the sum is", sum
elif choice == 2:
sub1 = input("first number: ")
sub2 = input("second number: ")
diff = sub1 - sub2
print "the difference is: ", diff
elif choice == 3:
mult1 = input ("first number: ")
mult2 = input ("second number: ")
product = mult1 * mult2
print "the product is: ", product
elif choice == 4:
print "SORRY, I FORGOT HOW TO DO DIVISION."
elif choice == 5:
print "what's an exponent???"
elif choice == 6:
loop = 2
print "thanks for using this calculator."
else:
print "What? I don't think I heard you right."
AND
calculator2.py (not a calculator obviously)
a = 1
phone = {}
phone['me'] = 1987654321
phone['you'] = 1234567890
phone['him'] = 1234543210
phone['her'] = 3141592653
def menu():
print ""
print "What would you like to do?"
print ""
print "1) View all names"
print "2) Find a phone number"
print "3) Create a new entry"
print "4) Quit"
print ""
choice = input("Select an option: ")
return choice
def entername():
name = raw_input ("Enter name: ")
return name
def enterage():
age = raw_input ("Enter age: ")
return age
def sortnames(names):
names.sort()
print names
def cont():
b = 0
while b == 0:
print ""
print "Select another option?"
print "1 - Yes"
print "2 - No"
dude = input("?")
if dude == 1:
b = 1
return 1
elif dude == 2:
b = 1
return 2
else:
b = 0
print "Welcome to MMYYY Phonebook version 1.uhh"
while a == 1:
print ""
choice = menu()
if choice == 1:
names = phone.keys()
names.sort()
print names
a = cont()
elif choice == 2:
try:
print phone[entername()]
except:
print "Name is not in the List"
a = cont()
elif choice == 3:
print "I don't know how to do that yet! SORRY."
a = cont()
elif choice == 4:
print "bye!"
a = 2
THAS IT
Saturday, June 6, 2009
Tuesday, June 2, 2009
Subscribe to:
Posts (Atom)