Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2012, 11:20 AM
Technewb Technewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 Technewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 45 sec
Reputation Power: 0
Python school assignment in python 3.2.3 HELP!

Hello I REALLY need help with an assignment, my teacher is very bad at teaching, and I need help the following is my assignment:

COMP 1030 - Programming Fundamentals
Assignment 3, Fall 2012

Due Date: Wednesday, December 5, 2012, midnight Max Marks: 40

Write the Python code for the following programming problem. Please code using Python 3.2.3.
Write a modular Python program that will calculate the cost of purchasing a meal. This program will include decisions and loops.
Details of the program are as follows:
Your menu items only include the following food with accompanied price:
Yum Yum Burger = $0.99
Grease Yum Fries = $0.79
Soda Yum = $1.09

Allow the user of the program to purchase any quantity 0 through 20, of these items on one order. So maximum of 20 for each of the burger, fries and soda can be ordered in one order. The user may choose not to order an item at all.
Allow the user to order any item more than once in the same order.
After the order is placed, calculate the sub-totals and the total. Add a 13% sales tax to total to produce the final purchasing price.
Print to the screen a receipt showing the total number of each item purchased, the sub-total amount of each item purchased (number purchased times price), the total amount, the tax on the total amount and then and the final purchase price.


Functions: These are the functions that MUST be coded. All prompts for required inputs must be complete and clear stating valid values, stopping condition etc. Similarly error messages must be clear and should say what went wrong. Please look at the input/output sample provided to see what I mean. These requirements carry marks in the associated functions.

main() function that controls the program and calls on the other functions as required.(4 marks)
getOrderNumber() that lets the user input a numeric order number (must be >= 0). The user is forced to enter a valid numeric value. It returns the valid value to the calling function.(4 marks)
showMenu() that shows the menu and receives the menu choice from the user. It validates the choice and forces the user to input till a valid value is supplied. If the choice is valid, it returns the menu choice to the calling function.(4 marks)
getItem(itemName, canOrderTheseMany) that inputs the number of items(burgers or fries or soda) ordered and returns it to the calling function. Please ensure that since this is a common function for ordering an ‘item’, the item name appears in the input message. Remember that the valid value is a number 0 through whateverIsLeftOfThatItem. (5 marks)
calculateItemCost(itemName, number_of_item) calculates the cost of the item purchased and returns it.(2 marks)
calculateTotalCost(burgersCost,friesCost, sodasCost) calculates and returns the total cost of the order. (2 marks)
calculateTax(totalCost)) that takes as input the total cost and calculates the tax on it. It returns the tax calculated.(2 marks)
calculateFinalCost(totalCost, tax) takes the total cost and the tax and calculates and returns the final cost. (2 marks)
printAll() function takes as input parameters all that need to be printed and prints the receipt on the screen. Please see sample output below. Your output MUST look exactly like the one provided. All output must be formatted. For currency amount and tax rate show two digits after the decimal point. (5 marks)

Notes:
The program should be well documented. Your name(s), date and purpose at the beginning. Each function must have an explanatory comment before its definition at the least. Please do not clutter your code with unnecessary comments though.(3 marks)

The program runs while the order number is greater than zero. It stops when the order number input is a value of 0.(1 mark)
The valid input in getOrderNumber() for order number is a numeric value >= 0. In case of invalid input, display an error message and let the user re-enter till a valid value is provided.
The only valid input choices for the menu items in showMenu() are 1, 2, 3 and 4. Validate the choice, giving appropriate error message in case of invalid input. Force user to re-enter till a valid choice is input.
The number of items purchased of any item must be numeric and should be from 0 through whateverIsLeftOfThatItem. Validate the input in the function getItem(itemName, canOrderTheseMany) whenever an item is ordered. Items can be ordered in ‘whole’ quantities only. Display meaningful error message in case of invalid input and force the user to re-enter till a valid value is entered. Return the valid value from this function.
Do not use any “magic numbers” in your code, either for calculations or for displaying purposes.(3 marks) Use named “global constants” for fixed values that you need in more than one functions and local constants in functions that require them .
All local variables, including the formal parameters need to be declared in comments in the function.(3 marks)
Please do not use global variables in the code. Communication between functions should be through parameter(s) and the return variable(s).

Sample Input and Output: Pay special attention to prompts and error messages. Notice the quantity of an item that can be ordered. The item name and the allowed limit appears with every item ordered. An item can be ordered more than once in an order. For each new order, the maximum quantity of any item ordered is fixed at 20 and reduces as the item order is placed.

======================== NEW ORDER==========================

Please enter order number (>=0). Enter 0 to stop the program: 1

START ORDER: 1

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 1

You can order 0 through 20 burgers.
Enter the number of burgers you want: 3

----------------------------------------------- M E N U ------------------------------------------------


Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 3

You can order 0 through 20 sodas.
Enter the number of sodas you want: 2

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 1

You can order 0 through 17 burgers.
Enter the number of burgers you want: 1


----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 2

You can order 0 through 20 fries.
Enter the number of fries you want: 2

----------------------------------------------- M E N U ------------------------------------------------


Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 3

You can order 0 through 18 sodas.
Enter the number of sodas you want: 20
Input error!!
You can order 0 through 18 sodas.
Enter the number of sodas you want: 0

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 4

--------------------Thanks for your order-----------------------


======================= R E C E I P T =========================
Number of burgers ordered :4
Sub-total (@ $.99 each) :$3.96
Number of fries ordered :2
Sub-total (@ $.79 each) :$1.58
Number of sodas ordered :2
Sub-total (@ $1.09 each) :$2.18
Total :$7.72
Tax at 13% :$1.00
-----------------------------------------------------------------
Final Purchase Price :$8.72



=========================== NEW ORDER=======================

Please enter order number (>=0). Enter 0 to stop the program: 2


START ORDER: 2

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 2

You can order 0 through 20 fries.
Enter the number of fries you want: 2

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 3

You can order 0 through 20 sodas.
Enter the number of sodas you want: 2

----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 2

You can order 0 through 18 fries.
Enter the number of fries you want: 2


----------------------------------------------- M E N U ------------------------------------------------

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order

Enter now -> 4

--------------------Thanks for your order-----------------------


======================== R E C E I P T ==========================
Number of burgers ordered :0
Sub-total (@ $.99 each) :$0.00
Number of fries ordered :4
Sub-total (@ $.79 each) :$3.16
Number of sodas ordered :2
Sub-total (@ $1.09 each) :$2.18
Total :$5.34
Tax at 13% :$0.69
-----------------------------------------------------------------
Final Purchase Price :$6.03


=========================== NEW ORDER=======================

Please enter order number (>=0). Enter 0 to stop the program: 0



Another run showing erroneous inputs from the user and error messages that are output.

=========================== NEW ORDER =========================
Please enter order number (>=0). Enter 0 to stop the program: -1
Input Error!
The order number must be 0 or greater.
Please enter order number (>=0). Enter 0 to stop the program: 1
START ORDER: 1
------------------- MENU ------------------
Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order
Enter now -> -2
Input Error!
You must select a value 1 through 4.
Enter now -> 5
Input Error!
You must select a value 1 through 4.
Enter now -> 1
You can order 0 through20 burgers.
Enter the number of burgers you want: -4
Input Error!
You can order 0 - 20 burgers.
Enter the number of burgers you want: 2
------------------- MENU ------------------
Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter 4 to end order
Enter now -> 4
----------------------Thanks for your order----------------------
========================= R E C E I P T =========================
Number of burgers ordered :2
Sub-total (@ $0.99 each) :$1.98
Number of fries ordered :0
Sub-total (@ $0.79 each) :$0.00
Number of sodas ordered :0
Sub-total (@ $1.09 each) :$0.00
Total :$1.98
Tax at 13.00% :$0.26
-----------------------------------------------------------------
Final Purchase Price :$2.24
=================================================================
=========================== NEW ORDER =========================
Please enter order number (>=0). Enter 0 to stop the program: 0


HOW TO SUBMIT:

Please submit the Python code only (.py file) via blackboard link for Assignment 3 by the due date. Please name it Assignment3_yourname(s).py


This is my code so far:

def main():
#loop forever, i.e. keep getting orders until input is 0
#every loop is an order
while (OrderNumber != 0)
print ("======================== NEW ORDER==========================")

#get the order number
#validate inside the function
#make sure number is >= 0
orderNumber = getOrderNumber()

#break exits out of the loop it is placed in
#if the input is 0, we want to stop the program
if(orderNumber == 0):break

#print out the order number
print ("START ORDER:") + str(orderNumber)

#keep getting items for this order until the user wants to end the order

#set initial quantities of items
#for EACH order, the limit is 20
numBurgersLeft = 0
numFriesLeft = 0
numSodasLeft = 0

#ordering stuff from the menu
while True:
#show user menu, get menu selection from them
#inside the function, we get input
#validate the input (1, 2, 3, 4)
#return that value
#menuItem 1 Yum Yum Burger
#menuItem 2 Greasy Yum Fries
menuItem = showMenu()

#get how many of the item we want
#i.e. if menuItem is 1 (Yum Yum Burger) and howManyOfItem is 2, then the person wants 2 Yum Yum Burgers
#need to tell person how many they can order and prompt for number
#need to check if quantity ordered is allowed

if menuItem == 1: #burger
#prompting taken care of in getitem
#passes back number that they want
#0 through number left of that item
howManyOfItem = getItem(menuItem, numBurgersLeft)
elif menuItem == 2:
#first parameter is the item
#second parameter is the number left
howManyOfItem = getItem(menuItem, numFriesLeft)
elif menuItem == 3:
howManyOfItem = getItem(menuItem, numSodasLeft)
else: break
#menuItem is 4 here. We want to end the order.
#what do we put here to end the order, i.e. break out of loop?
#hint: the keyword to break out of a loop was used earlier


#subtract from the quantity left
#need to know which item it is (so we know which quantity to subtract from)
#then subtract number ordered

numBurgersLeft <-----
numFriesLeft
numSodasLeft

#this isn't code
15 burgers left
numBurgersLeft = 15
5 burgers ordered
howManyOfItem = 5

#

if menuItem == 1:
#want this to be new numBurgersLeft <----
# = <- assign values
#assignment operator
# left hand side: variable, not 5, "hello"
# right hand side: value, 5, "hello", variable

numBurgersLeft = numBurgersLeft - howManyOfItem #these two are equivalent
#numBurgersLeft -= howManyOfItem

elif menuItem == 2:


numFriesLeft -=howManyOfItem

else: menuItem == 3:

numSodaLeft -=howManyOfItem



#out of the loop that gets all the items for the order now
print "--------------------Thanks for your order-----------------------"
#order is now complete, want to calculate receipt
#hint: number of burgers ordered is 20 - numBurgersLeft
numBurgersOrdered = 20 - numBurgersLeft

#do same for other menu items

#calculate costs <-----
#get burger cost
#hint: first parameter is the itemName (1)
# second parameter is the number ordered
burgersCost = calculateItemCost(1, numBurgersOrdered)

#can you fill in how to get the other costs?

#get total cost <---------------
totalCost = calculateTotalCost(burgersCost, friesCost, sodasCost) #calculates and returns the total cost of the order. (2 marks)
tax = calculateTax(totalCost) #that takes as input the total cost and calculates the tax on it. It returns the tax calculated.(2 marks)\
finalCost = calculateFinalCost(totalCost, tax) #takes the total cost and the tax and calculates and returns the final cost. (2 marks)

#print the receipt
#what values do we want to print?
printAll(totalCost, tax,........) #function takes as input parameters all that need to be printed and prints the receipt on the screen.





I really need help with this can anyone give me guidance?

Reply With Quote
  #2  
Old December 4th, 2012, 02:14 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
Please use code tags---follow instructions at my signature for posting code. Thanks.

What part have you written? I take it you didn't write
Code:
#hint: the keyword to break out of a loop was used earlier


Maybe you wrote
Code:
#this isn't code
15 burgers left
numBurgersLeft = 15
5 burgers ordered
howManyOfItem = 5



I don't see a clear way to guide you. I can't bypass the next-to-useless order number. You don't store the order by number and pass it back to the chef. The order number should be automatically assigned, unless it's zero. The assignment seems unreasonable because I wouldn't ask so many damn questions. My main program would probably read
Code:
def main():
    while orders():
        pass
Simple. All functions short and simple. Use many functions.
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : December 4th, 2012 at 02:16 PM.

Reply With Quote
  #3  
Old December 4th, 2012, 07:17 PM
Technewb Technewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 Technewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Please use code tags---follow instructions at my signature for posting code. Thanks.

What part have you written? I take it you didn't write
Code:
#hint: the keyword to break out of a loop was used earlier


Maybe you wrote
Code:
#this isn't code
15 burgers left
numBurgersLeft = 15
5 burgers ordered
howManyOfItem = 5



I don't see a clear way to guide you. I can't bypass the next-to-useless order number. You don't store the order by number and pass it back to the chef. The order number should be automatically assigned, unless it's zero. The assignment seems unreasonable because I wouldn't ask so many damn questions. My main program would probably read
Code:
def main():
    while orders():
        pass
Simple. All functions short and simple. Use many functions.


Okay, I have narrowed my code down to this:

#Mark Rourke, Mitch Lavalle
#Dec 04, 2012

#Global Constants
#Constant Integer MAX_QTY
MAX_QTY = 20
#Constant Real TAX_RATE
TAX_RATE = .13

def main():
#Integer Constant STOP = 0`
STOP = 0


print ("======================== NEW ORDER==========================")

#get the order number
#validate inside the function
#make sure number is >= 0
orderNumber = getOrderNumber()

#break exits out of the loop it is placed in
#if the input is 0, we want to stop the program
while (orderNumber != 0):
burgersLeft = 0
friesLeft = 0
sodasLeft = 0


#print out the order number
print ("START ORDER:") + str(orderNumber)



#keep getting items for this order until the user wants to end the order

#set initial quantities of items
#for EACH order, the limit is 20


menuItem = showMenu()

#ordering stuff from the menu
while (menuItem!= 4):
#show user menu, get menu selection from them
#inside the function, we get input
#validate the input (1, 2, 3, 4)
#return that value
#menuItem 1 Yum Yum Burger
#menuItem 2 Greasy Yum Fries

#get how many of the item we want
#i.e. if menuItem is 1 (Yum Yum Burger) and howManyOfItem is 2, then the person wants 2 Yum Yum Burgers
#need to tell person how many they can order and prompt for number
#need to check if quantity ordered is allowed

if menuItem == 1: #burger
#prompting taken care of in getitem
#passes back number that they want
#0 through number left of that item
burgersLeft = getItem(1,MAX_QTY - burgersLeft)
elif menuItem == 2:
#first parameter is the item
#second parameter is the number left
friesLeft = getItem(2,MAX_QTY - friesLeft)
elif menuItem == 3:
sodasLeft = getItem(3,MAX_QTY - sodasLeft)
else: break
#menuItem is 4 here. We want to end the order.
#what do we put here to end the order, i.e. break out of loop?
#hint: the keyword to break out of a loop was used earlier


#subtract from the quantity left
#need to know which item it is (so we know which quantity to subtract from)
#then subtract number ordered






if menuItem == 1:
#want this to be new numBurgersLeft <----
# = <- assign values
#assignment operator
# left hand side: variable, not 5, "hello"
# right hand side: value, 5, "hello", variable

burgersOrdered = burgersLeft - MAX_QTY
burgersLeft = burgersLeft + burgersOrdered

elif menuItem == 2:


friesOrdered = friesLeft - MAX_QTY
friesLeft = friesLeft + friesOrdered

elif menuItem == 3:

sodasOrdered = sodasLeft - MAX_QTY
sodasLeft = sodasLeft + sodasOrdered



#Calculate the cost of each item

costOfBurgers = calculateCost (1, burgersOrdered)
costOfFries = calculateCost (2, friesOrdered)
costOfSodas = calculateCost (3, sodasOrdered)


totalCost = CalculateTotalCost(1,2,3 + totalTax)
tax = calculateTax(totalCost * .13)

finalCost = calculateFinalPrice(TotalCost + tax)

I know it needs work but i dont know what to do, can you please give me some functions to work with?

Reply With Quote
  #4  
Old December 4th, 2012, 08:29 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
Many little functions. This code may get you started. It handles generalized prompting and the outer loop order number crap including error handling. Should work with python 2 or with python 3 although I only tested with python 2. You're to target python 3.l
Code:
import sys

def my_prompt(message,error_message,conversion,validate):
    while True:
        sys.stdout.write(message)
        text = sys.stdin.readline()
        try:
            result = conversion(text)
        except:
            pass
        else:
            if validate(result):
                return result
        sys.stdout.write('Input Error!\n')
        sys.stdout.write(error_message+'\n')

def getOrderNumber():

    def non_negative(x):
        return abs(x) == x

    return my_prompt(
        'Please enter order number (>=0).  Enter 0 to stop the program: ',
        'The order number must be 0 or greater.',
        int,
        non_negative)

def order(orderNumber):
    print('START ORDER: %s'%orderNumber)
    print('blah blah blah')

def ordering():
    print('======================== NEW ORDER==========================')
    n = getOrderNumber()
    if n: order(n)
    return n

def main():
    while ordering():
        pass

Reply With Quote
  #5  
Old December 6th, 2012, 01:58 PM
Technewb Technewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 Technewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 45 sec
Reputation Power: 0
Code:
#Mark Rourke, Mitch Lavalle
#Dec 04, 2012
#Global Constants
#Constant Integer MAX_QTY
MAX_QTY = 20
#Constant Real TAX_RATE
TAX_RATE = .13
#Constant Real Burger
Burger = .99
#Constant Real Fries
Fries = .79
#Constant Real Soda
Soda = 1.09
import sys
def getOrderNumber():
#Get the order number from user
#orderNumber >=0
    goodOrder = True
    while goodOrder == True:
        try:
            orderNumber = int(input("Please enter order number, Enter 0 to Stop"))
        except ValueError:
            print("Non numeric input entered. Program terminating...")
        except:
            print("Input Error")
        else:
            if (orderNumber > 0):
                print ("Your order Number is %d" %(orderNumber))
                return orderNumber
            elif (orderNumber < 0 or orderNumber != 0):
                goodOrder = True
                print ("Please enter a proper value")
           
                
                
                
                
def showMenu():
#THIS IS ALL PART OF SHOWMENU: 
        #keep getting items for this order until the user wants to end the order
                     #set initial quantities of items
    numBurgers=20;
    numFries=20;
    numSodas=20;
    menuItem = showMenu()<---------ERROR THERE<----
                #ordering stuff from the menu
    menuItem=-1

    while (menuItem!= 0): 
                        #show user menu
                         print("    ----------------------------------------------- M E N U ------------------------------------------------")

    print ("Your order Number is %d")

    print("Cost of Burger: %.2f" %Burger)

    print("Cost of Fries: %.2f" %Fries)

    print("Cost of Soda: %.2f" %Soda)

    print("Enter 1 for Yum Yum Burger")

    print("Enter 2 for Grease Yum Fries")

    print("Enter 3 for Soda Yum")

    print("Enter 0 to end order")

    #get menu selection from them

    itemType = int(input("Enter now->"))
                        #inside the function, we get input
                        #validate the input (1, 2, 3, 4)
                        #return that value
                        #menuItem 1 Yum Yum Burger
                        #menuItem 2 Greasy Yum Fries
                        #get how many of the item we want
                        #i.e. if menuItem is 1 (Yum Yum Burger) and howManyOfItem is 2, then the person wants 2 Yum Yum Burgers
                        #need to tell person how many they can order and prompt for number
                        #need to check if quantity ordered is allowed
                        
    if menuItem == 1:
        #burger 
        print("You can order 0 through"+numBurgers+"burgers.") 
        numBurgAsked=input("how many would you like?")
        #prompting taken care of in getitem
        #passes back number that they want
    if(numBurgAsked<=numBurgers):
        numBurgers = numBurgers - numBurgAsked
    elif menuItem == 2:
        print("You can order 0 through"+numFries+"fries.") 
        numFriesAsked=input("how many would you like?")
    if(numFriesAsked<=numFries):
        numBurgers = numBurgers - numBurgAsked
    elif menuItem == 3:
        print("You can order 0 through"+numSodas+"sodas.")
        numSodasAsked=input("how many would you like?")
    if(numSodasAsked<=numFries):
        numSodas = numSodas - numSodasAsked
           
#THIS IS PART OF CALCULATEFINALCOST:
        #Calculate the cost of each item
        costOfBurgers = calculateCost (1, burgersOrdered)
        costOfFries = calculateCost (2, friesOrdered)
        costOfSodas = calculateCost (3, sodasOrdered)
        totalCost = CalculateTotalCost(1,2,3 + totalTax)
        tax = calculateTax(totalCost * TAX_RATE)
        finalCost = calculateFinalPrice(TotalCost + tax)
        
def main():
    getOrderNumber()
    showMenu()
main()
            



Okay this is what I've got so far on like 47 i have stated menuItem = showMenu()<---------ERROR THERE<----,
thats where I'm getting the error, it goes into an infinate loop stating "File "C:\Users\Mark\Desktop\Assignment3_MarkRourke.py", line 45, in showMenu
menuItem = showMenu()"
can you give me some sort of way to get out of this?

Reply With Quote
  #6  
Old December 6th, 2012, 02:21 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
Your code calls showMenu from within showMenu without a termination condition. How would you expect this program to operate?

def f():
f()

f()

Reply With Quote
  #7  
Old December 6th, 2012, 02:23 PM
Technewb Technewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 Technewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Your code calls showMenu from within showMenu without a termination condition. How would you expect this program to operate?

def f():
f()

f()


i can see the def f function you put how would i put the termination function in the code?

Reply With Quote
  #8  
Old December 6th, 2012, 03:34 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
Code:
def factorial(n):  # factorial should be memo-ized
    if n < 3:     # THIS STOPS THE RECURSION
        return max(1,n)
    return n*factorial(n-1)               # RECURSION

for i in range(9):
    print(i,factorial(i))

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python school assignment in python 3.2.3 HELP!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap