samedi 25 octobre 2014

Python: Using defs in a program about ordering stuff


Vote count:

0




This program is about ordering stuff from a "mail order" house thing.


They sell five products. P1 = 2.98, P2 = 4.5, P3 = 9.98, P4 = 4.49, P5 = 6.87


So this is my code so far.



#Imports: None

#Defs:

def userInput1():
x = int(input("Product Number?")
return x
def userInput2():
q = int(input("Quantity?")
return q
def calculations(x,q):
p1 = 2.98
p2 = 4.5
p3 = 9.98
p4 = 4.49
p5 = 6.87
subtotal = q * x
return subtotal
def final(subtotal):
print ("Total:", subtotal)
def loop():
print ("Do you want to continue? (yes/no)")
cont = raw_input()
if cont = 'yes':
main()
return
else:
final()

def main()
x = userinput()
subtotal = calculations()
final(subtotal)

#Driver:
main()


I have to use a sentinel controlled loop.


Here's how it should work.



Product number?: 1
Quantity?: 2
Continue?(yes/no): yes
Product number?: 2
Quantity?: 5
Continue?(yes/no): yes
Product number?: 3
Quantity?: 3
Continue?(yes/no): yes
Product number?: 4
Quantity?: 1
Continue?(yes/no): no
Total: $62.89


I keep getting syntax error when I use return. Please help!



asked 7 mins ago







Python: Using defs in a program about ordering stuff

Aucun commentaire:

Enregistrer un commentaire