4 Replies - 1294 Views - Last Post: 24 May 2012 - 12:01 AM Rate Topic: -----

#1 CapsuleMantis62  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 16-May 12

how can i make this code smaller and working?

Posted 20 May 2012 - 09:54 PM

#What pizza's. Delivery or pick up?
#IF THE ORDER IS FOR DELIVERY:
#A 3$ delivery charge to be added to the total cost.
#Get customers name, address and phone number (contact details).
#Show pizza's and prices.

#IF THE ORDER IS FOR PICK UP:
#Get customers name. 
#Show pizza's and prices.

#Pizza's
1 = ("Apricot Chicken $13.50")
2 = ("Meat Lovers $13.50") 
3 = ("Vegetarian $13.50") 
4 = ("Double Cheese $13.50")
5 = ("Hawaiian $13.50")
6 = ("Pepperoni $8.50")
7 = ("Beef and Onion $8.50")
8 = ("Ham and Cheese $8.50")
9 = ("Tomato Margherita $8.50")
10 = ("Classic Italian $8.50")
11 = ("BBQ Chicken and Bacon $8.50")
12 = ("Italian Veg $8.50")

def hi ():
    pass
while True:
    try:
        D/P = (input("What pizza's do you want?"))
        break
    except ValueError:
        pass
    
    print ("Sorry. What ever you said is not a valid entry, try again!")
def hi2 ():
    pass
while True:
    try:
        Pizza = (input("how do you want to recive the pizza's?.. Delivery or Pick up"))
        if Pizza == 'D':
            Contact = (input("What is your Name, Delivery address and Contact details?"))
            print ("It's going to cost you...") 
            print ("$",#Here i need a code to add the pizza's prices together and the delivery charge of $3.
            print (("Your ordering") , D/P ,"Pizza's")
            print (("Thank you") , Contact ,".")
            break
        if Pizza == 'P':
            print ("It's going to cost you...") 
            print ("$",#Here i need a code to add the pizza's prices together.
            print (("Thank you for ordering") , D/P ,"Pizza's")            
            break
        elif Pizza != 'D' or 'P':
            print ("You need to tell me if you want it Delivered or Pick up!")
    except:
        pass 


i need to figure out a math code for the adding of pizza's and delivery charge.
Where it says "print (("Thank you") , Contact ,".")" it don't seem to work.
And also make a loop in it so the customer can cancel the order at anytime, and restarts it or just quit (deleting what ever the customer has put in.

Is This A Good Question/Topic? 0
  • +

Replies To: how can i make this code smaller and working?

#2 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: how can i make this code smaller and working?

Posted 21 May 2012 - 05:32 AM

Okay, there are several things to fix here.

First, you're defining two functions, hi() and hi2(), neither of which actually do anything. If you want your code to be part of the functions, you need to indent it. Also, remove the pass.

Second, on line 29, you try to assign a value to D/P. You can't do that. A variable name can't have '/' in it.

Third, on line 52 you have the following:
elif Pizza != 'D' or 'P':



You can't do it like that, because 'P' will always evaluate to True. You need to either do something like this:
elif Pizza != 'D' or Pizze != 'P':



...or change line 47 to say elif rather than if, and then change line 52 to say:
else:


For adding the pizza prices together... well, how are you expecting the input to be formatted? You'll need to find the prices of each pizza and add them together, but for that you need to know what input you'll recieve.
Was This Post Helpful? 0
  • +
  • -

#3 CapsuleMantis62  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 16-May 12

Re: how can i make this code smaller and working?

Posted 22 May 2012 - 03:16 PM

[quote name='Tayacan' date='21 May 2012 - 05:32 AM' timestamp='1337603542' post='1627335']
book_cost = 24.95
discount = .6
shipping_first_book = 3
copys = .75
print ("Ryan, 12th of March 2012. Bookstore costing calculator")
print ("Welcome to your book supplier.")
print ("Books cost $24.95 each")
print ("The first book cost $3 to ship and extra copys cost only .75c")
def hi ():
    pass
while True:
    try:
        books = int(input("How many books do you want to order? "))
        break
    except ValueError:
        pass
    
    print ("Sorry. What ever you said is not a number, try again!")
def hi2 ():
    pass
while True:
    try:
        Shop = (input("Are you a shop owner? (Yes or No) "))
        if Shop == 'yes':
            print ("Since you are bookstore owner, you get a 40% discount.")
            print ("It's going to cost you...") 
            print ("$",(books * book_cost) * (discount) + (books * copys) - (copys) + shipping_first_book)
            print (("Thank u for odering") , books ,"books")
            break
        if Shop == 'no':
            print ("It's going to cost you...") 
            print ("$",(books * book_cost) + (books * copys) - (copys) + shipping_first_book)
            print (("Thank you for odering") , books ,"book(s)")
            break
        elif Shop != 'yes' or 'no' or 'Yes' or 'No' or 'n' or 'y':
            print ("You need to tell me if you are a shop owner or not, not just giving me random letters, it is not appropriate!")
            
    except:
        pass



how come this one works then?
Was This Post Helpful? 0
  • +
  • -

#4 CapsuleMantis62  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 16-May 12

Re: how can i make this code smaller and working?

Posted 23 May 2012 - 05:19 PM

#What pizza's. Delivery or pick up?
#IF THE ORDER IS FOR DELIVERY:
#A 3$ delivery charge to be added to the total cost.
#Get customers name, address and phone number (contact details).
#Show pizza's and prices.

#IF THE ORDER IS FOR PICK UP:
#Get customers name. 
#Show pizza's and prices.

a = ("8.50")
b = ("13.50")
def hi1 ():
    pass
while True:
    try:
        Pizza = (input("how do you want to recive the pizza's?...Delivery = 1 or Pick up = 2 "))
        if Pizza == '1':
            Delivery = (input("What's your name? "))
            Delivery_con = (input("What's your contact details? "))
            Delivery_add = (input("what's your address details? "))
            break
        if Pizza == '2':
            Pick_up = (input("What's your name? "))
            Pick_up_con = (input("whats your contact details"))
            break
        elif Pizza != '1' or '2':
            print ("You need to tell me if you want it Delivered or Pick up!")
    except:
        pass 

def hi2 ():
    pass
while True:
    try:
        Pizza = (input("hello"))
        if Pizza == '3':
            print ("...")
            break
        if Pizza == '4':
            print ("......")           
            break
        elif Pizza != '1' or '2':
            print ("You need to tell me if you want it Delivered or Pick up!")
    except:
        pass 

Was This Post Helpful? 0
  • +
  • -

#5 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 124
  • Joined: 08-May 11

Re: how can i make this code smaller and working?

Posted 24 May 2012 - 12:01 AM

Here, I didn't completely finish the program, just wrote it to get it working somewhat like you wanted and hopefully help you out. Ask me questions if you're confused or whatever.

pizza_d = {
1 : ("Apricot Chicken $13.50"),
2 :(/>"Meat Lovers $13.50") ,
3 : ("Vegetarian $13.50") ,
4 : ("Double Cheese $13.50"),
5 : ("Hawaiian $13.50"),
6 : ("Pepperoni $8.50"),
7 : ("Beef and Onion $8.50"),
8 : ("Ham and Cheese $8.50"),
9 : ("Tomato Margherita $8.50"),
10 : ("Classic Italian $8.50"),
11 : ("BBQ Chicken and Bacon $8.50"),
12 : ("Italian Veg $8.50")
}
while 1:
	while 1:
		try:
			num_pizzas = int(raw_input('How many pizzas do you want to order?'))
			break
		except ValueError:print ("invalid choice")
	#show_menu()
	x = 1 
	pizzas=[]
	prices=[]
	buf = []
	while x<= num_pizzas:
		while 1:
			try:
				pizza = int(raw_input("Which pizza do you want to order?"))
				if pizza in pizza_d: 
					pizzas.append(pizza_d[pizza])
					buf = pizzas[x-1].split('$')
					prices.append(buf.pop())
					break
				else: continue
			except ValueError: 
				print ("invalid choice")
				continue
		x+=1
	#add total 
	total = 0
	for price in prices:
		total += float(price)
		
	#still need to add errorchecking to make sure d or p was entered
	d_or_p = raw_input('Delivery or Pickup?')
	d_or_p.lower()
	if d_or_p == 'd' or d_or_p == 'delivery':
		#do stuff for delivery
		total+=3.0
		print "you ordered ", len(pizzas), "pizzas:"
		for pizza in pizzas:
			print pizza
		print "your total is $", total
	elif d_or_p == 'p' or d_or_p == 'pickup':
		print "you ordered", len(pizzas),"pizzas:"
		for pizza in pizzas:
			print pizza
		print "your total is $", total
		
	



Edit: Your code above is working because it's all valid and everything. The point is that your functions aren't doing anything other than taking up space because the pass is there, which is just a space filler for when you have to have a function do something but don't want it to do anything. Anyways, good luck man and have a nice night/day.

This post has been edited by alexr1090: 24 May 2012 - 12:07 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1