4 Replies - 743 Views - Last Post: 28 November 2012 - 05:11 PM Rate Topic: -----

#1 littlePilot  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 07-March 12

how to get this code to restart

Posted 27 November 2012 - 05:00 PM

def main():
  pass
menu = [('Pricot Chicken', 8.50), ('Meat Lovers', 13.50), ('Vegetarian', 13.50), ('Double Cheese', 13.50), ('Hawaiian', 13.50), ('Pepperoni', 8.50), ('Beef and Onion', 8.50), ('Ham and Cheese', 8.50), ('Tomato Margherita', 8.50), ('Classic Italian', 8.50), ('BBQ Chicken and Bacon', 8.50), ('Italian Veg', 8.50)]

print ("Wellcome to Ethans Pizza Code")

name1 = (input("What is your order name: "))


def D_or_P(): # error checked to make sure yes or no is entured if not it will repeat till it is.
  pass
question_not_answered = True
while (question_not_answered):
  d_or_p =input("Will this order Be Delivery? (yes or no): ").lower()
  if (d_or_p == 'yes'):
    d_or_p = 3
    question_not_answered = False      
  elif (d_or_p == 'no'):
    d_or_p = 0
    question_not_answered = False
  else:
    print('Error: Not a yes or no')

if d_or_p in (range (3,4)): # only asks these if d_or_p = yes 
  PH = input ("what is your phone number?: ") # cant get it to loop if no number is entered so i had to leave it otherwise it would crash
  Ad = input ("what is your address: ") 

	    

# done
def num_pizzas(): # asks what pizzas you would like to order if any number ordered thats not 1-5 it will repeted till it is 
    pass
while True:
    try:
        num_pizzas= int (input('How many pizzas do u want to buy? (limit 5): '))
        if num_pizzas in (range (1, 6)):
            break
        elif num_pizzas not in (range (1, 6)):
            pass
    except ValueError:
        pass
    print ("Please enter number betwen 1- 5")



fmt, nfmt = '{0:<30} {1:>9} {2:>9}'.format, '{0:0.2f}'.format #formats menu to use names and prices in reset

print('\n'.join('{0:>3}. {1:<30} {2:>9}'.format(i+1, name, (" $")+nfmt(price)) for i, (name, price) in enumerate(menu))) # splits menu into price and name and prints the menu

print ("What pizzas would you like to order? separated by a space (please type in the numebr for the pizza)")
print (("please note if you order any more pizzas then"),num_pizzas,("they will be removoed from the order and not counted by the order.\n but you can enter less then"),num_pizzas,("if you dont like the choices very much"))
print ("any numbers you enter that are not a pizza will not be counted")



order = ([ i for i in (int(s)-1 for s in input().split() if s.isdigit()) if i in range(len(menu)) ]) #splits numbers entred to be used in order
del order [num_pizzas:] #deletes extra numbers that aren't alowed 
# cant limt the amount of pizzas in order so i deleted the rest of them but the customer is told this.


print (("order for"),name1) # prints your name you typed in earlier
print("Your order:")
print(fmt('Item', 'Price', 'Total'))
total = 0.0
for i in order:
	name, price = menu[i]
	total += price
	print(fmt(name, (" $")+nfmt(price), (" $")+nfmt(total))) #prints name price and total so far with the pizzas

print(fmt('delivery', (" $")+nfmt(d_or_p), (" $")+nfmt(total))) # adds delivery charge to total cost
print(fmt('Grand Total','', (" $")+nfmt(total+ d_or_p))) #prints total cost

if d_or_p  in (range (3,4)): #only prints if delivery is yes
    print (("your address is"),Ad,("your phone number is"),PH,)
elif d_or_p not in (range (3,4)):
    print ("") 
    
print ("Thanks for using Ethans python pizza code thank you come agian")


new_order = input("would u like to make another order?") #need to loop to start




i would like to know how to get this code to restart from the beginning if new_order == yes thanks

Is This A Good Question/Topic? 0
  • +

Replies To: how to get this code to restart

#2 Python_4_President  Icon User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 321
  • Joined: 13-August 11

Re: how to get this code to restart

Posted 27 November 2012 - 07:06 PM

Lol.. Never seen someone define a bunch of functions that do nothing but (apparently) mark portions of the code.

def main():
	menu = [('Pricot Chicken', 8.50), ('Meat Lovers', 13.50), ('Vegetarian', 13.50), ('Double Cheese', 13.50), ('Hawaiian', 13.50), ('Pepperoni', 8.50), ('Beef and Onion', 8.50), ('Ham and Cheese', 8.50), ('Tomato Margherita', 8.50), ('Classic Italian', 8.50), ('BBQ Chicken and Bacon', 8.50), ('Italian Veg', 8.50)]

	print ("Wellcome to Ethans Pizza Code")

	name1 = (input("What is your order name: "))


	def D_or_P(): # error checked to make sure yes or no is entured if not it will repeat till it is.
	  pass
	question_not_answered = True
	while (question_not_answered):
	  d_or_p =input("Will this order Be Delivery? (yes or no): ").lower()
	  if (d_or_p == 'yes'):
	    d_or_p = 3
	    question_not_answered = False      
	  elif (d_or_p == 'no'):
	    d_or_p = 0
	    question_not_answered = False
	  else:
	    print('Error: Not a yes or no')

	if d_or_p in (range (3,4)): # only asks these if d_or_p = yes 
	  PH = input("what is your phone number?: ") # cant get it to loop if no number is entered so i had to leave it otherwise it would crash
	  Ad = input("what is your address: ") 

		    

	# done
	def num_pizzas(): # asks what pizzas you would like to order if any number ordered thats not 1-5 it will repeted till it is 
	    pass
	while True:
	    try:
		num_pizzas= int (input('How many pizzas do u want to buy? (limit 5): '))
		if num_pizzas in (range (1, 6)):
		    break
		elif num_pizzas not in (range (1, 6)):
		    pass
	    except ValueError:
		pass
	    print ("Please enter number betwen 1- 5")



	fmt, nfmt = '{0:<30} {1:>9} {2:>9}'.format, '{0:0.2f}'.format #formats menu to use names and prices in reset

	print('\n'.join('{0:>3}. {1:<30} {2:>9}'.format(i+1, name, (" $")+nfmt(price)) for i, (name, price) in enumerate(menu))) # splits menu into price and name and prints the menu

	print ("What pizzas would you like to order? separated by a space (please type in the numebr for the pizza)")
	print (("please note if you order any more pizzas then"),num_pizzas,("they will be removoed from the order and not counted by the order.\n but you can enter less then"),num_pizzas,("if you dont like the choices very much"))
	print ("any numbers you enter that are not a pizza will not be counted")



	order = ([ i for i in (int(s)-1 for s in input().split() if s.isdigit()) if i in range(len(menu)) ]) #splits numbers entred to be used in order
	del order [num_pizzas:] #deletes extra numbers that aren't alowed 
	# cant limt the amount of pizzas in order so i deleted the rest of them but the customer is told this.


	print (("order for"),name1) # prints your name you typed in earlier
	print("Your order:")
	print(fmt('Item', 'Price', 'Total'))
	total = 0.0
	for i in order:
		name, price = menu[i]
		total += price
		print(fmt(name, (" $")+nfmt(price), (" $")+nfmt(total))) #prints name price and total so far with the pizzas

	print(fmt('delivery', (" $")+nfmt(d_or_p), (" $")+nfmt(total))) # adds delivery charge to total cost
	print(fmt('Grand Total','', (" $")+nfmt(total+ d_or_p))) #prints total cost

	if d_or_p  in (range (3,4)): #only prints if delivery is yes
	    print (("your address is"),Ad,("your phone number is"),PH,)
	elif d_or_p not in (range (3,4)):
	    print ("") 
	    
	print ("Thanks for using Ethans python pizza code thank you come agian")

if __name__ == "__main__":
	main()
	while True:
		new_order = input("would u like to make another order?") #need to loop to start
		if new_order == "yes":
			main()
		else:
			break






I stuck all your code in your unused main function and created a loop at the bottom that starts the order process, once that's done, it asks the user if he wants to do it again, if so, go ahead, else quit.
Was This Post Helpful? 1
  • +
  • -

#3 Hqtitan  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 51
  • Joined: 28-August 10

Re: how to get this code to restart

Posted 28 November 2012 - 01:04 AM

Creating an infinite loop and then using break to get out of it seems counter intuitive. Why not use something like the following?

new_order = "yes"
while(new_order == "yes"):
    main()
    new_order = input("Would you like to place another order? (yes/no)")

Was This Post Helpful? 0
  • +
  • -

#4 littlePilot  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 07-March 12

Re: how to get this code to restart

Posted 28 November 2012 - 04:21 PM

View PostPython_4_President, on 27 November 2012 - 07:06 PM, said:

Lol.. Never seen someone define a bunch of functions that do nothing but (apparently) mark portions of the code.

def main():
	menu = [('Pricot Chicken', 8.50), ('Meat Lovers', 13.50), ('Vegetarian', 13.50), ('Double Cheese', 13.50), ('Hawaiian', 13.50), ('Pepperoni', 8.50), ('Beef and Onion', 8.50), ('Ham and Cheese', 8.50), ('Tomato Margherita', 8.50), ('Classic Italian', 8.50), ('BBQ Chicken and Bacon', 8.50), ('Italian Veg', 8.50)]

	print ("Wellcome to Ethans Pizza Code")

	name1 = (input("What is your order name: "))


	def D_or_P(): # error checked to make sure yes or no is entured if not it will repeat till it is.
	  pass
	question_not_answered = True
	while (question_not_answered):
	  d_or_p =input("Will this order Be Delivery? (yes or no): ").lower()
	  if (d_or_p == 'yes'):
	    d_or_p = 3
	    question_not_answered = False      
	  elif (d_or_p == 'no'):
	    d_or_p = 0
	    question_not_answered = False
	  else:
	    print('Error: Not a yes or no')

	if d_or_p in (range (3,4)): # only asks these if d_or_p = yes 
	  PH = input("what is your phone number?: ") # cant get it to loop if no number is entered so i had to leave it otherwise it would crash
	  Ad = input("what is your address: ") 

		    

	# done
	def num_pizzas(): # asks what pizzas you would like to order if any number ordered thats not 1-5 it will repeted till it is 
	    pass
	while True:
	    try:
		num_pizzas= int (input('How many pizzas do u want to buy? (limit 5): '))
		if num_pizzas in (range (1, 6)):
		    break
		elif num_pizzas not in (range (1, 6)):
		    pass
	    except ValueError:
		pass
	    print ("Please enter number betwen 1- 5")



	fmt, nfmt = '{0:<30} {1:>9} {2:>9}'.format, '{0:0.2f}'.format #formats menu to use names and prices in reset

	print('\n'.join('{0:>3}. {1:<30} {2:>9}'.format(i+1, name, (" $")+nfmt(price)) for i, (name, price) in enumerate(menu))) # splits menu into price and name and prints the menu

	print ("What pizzas would you like to order? separated by a space (please type in the numebr for the pizza)")
	print (("please note if you order any more pizzas then"),num_pizzas,("they will be removoed from the order and not counted by the order.\n but you can enter less then"),num_pizzas,("if you dont like the choices very much"))
	print ("any numbers you enter that are not a pizza will not be counted")



	order = ([ i for i in (int(s)-1 for s in input().split() if s.isdigit()) if i in range(len(menu)) ]) #splits numbers entred to be used in order
	del order [num_pizzas:] #deletes extra numbers that aren't alowed 
	# cant limt the amount of pizzas in order so i deleted the rest of them but the customer is told this.


	print (("order for"),name1) # prints your name you typed in earlier
	print("Your order:")
	print(fmt('Item', 'Price', 'Total'))
	total = 0.0
	for i in order:
		name, price = menu[i]
		total += price
		print(fmt(name, (" $")+nfmt(price), (" $")+nfmt(total))) #prints name price and total so far with the pizzas

	print(fmt('delivery', (" $")+nfmt(d_or_p), (" $")+nfmt(total))) # adds delivery charge to total cost
	print(fmt('Grand Total','', (" $")+nfmt(total+ d_or_p))) #prints total cost

	if d_or_p  in (range (3,4)): #only prints if delivery is yes
	    print (("your address is"),Ad,("your phone number is"),PH,)
	elif d_or_p not in (range (3,4)):
	    print ("") 
	    
	print ("Thanks for using Ethans python pizza code thank you come agian")

if __name__ == "__main__":
	main()
	while True:
		new_order = input("would u like to make another order?") #need to loop to start
		if new_order == "yes":
			main()
		else:
			break






I stuck all your code in your unused main function and created a loop at the bottom that starts the order process, once that's done, it asks the user if he wants to do it again, if so, go ahead, else quit.


its for school thats why its got all the # staments in. but when i tryed to do the same thing as you did i just couldnt get it to work :/... so i thank you :D!
Was This Post Helpful? 0
  • +
  • -

#5 Python_4_President  Icon User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 321
  • Joined: 13-August 11

Re: how to get this code to restart

Posted 28 November 2012 - 05:11 PM

You should take some time to turn those def statements-as-comments into real functions.

What does the function D_or_P need to do?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1