Pseudocode to Python 2.7 Multiple Errors -


i working homework assignment , can not understand doing wrong in code conversion. having multiple issues, described under code have. assigned question , pseudocode below:

>write python code following burger joint: >•  menu items include following food accompanied price:  >o  yum yum burger = .99 >o  grease yum fries = .79 >o  soda yum = 1.09 >•  allow user of program purchase quantity of these items on 1 order.  >•  allow user of program purchase 1 or more types of these items on 1 >order. >•  after order placed, calculate total , add 6% sales tax.  >•  print screen receipt showing total purchase price. 

here pseudocode:

module main()  call declarevariables(endprogram, endorder, totalburger, totalfry, totalsoda, total, tax, subtotal, option, burgercount, frycount, sodacount)  //loop run program again while endprogram == “no”      call resetvariables(totalburger, totalfry, totalsoda, total, tax, subtotal)          //loop take in order     while endorder == “no”         display “enter 1 yum yum burger”         display “enter 2 grease yum fries”         display “enter 3 soda yum”         input option         if option == 1             call getburger(totalburger, burgercount)         else if option == 2             call getfry(totalfry, frycount)         else if option == 3             call getsoda(totalsoda, sodacount)         end if  display “do want end order? (enter no add more items: )” input endorder     end while  call calctotal(burgertotal, frytotal, sodatotal, total, subtotal, tax) call printreceipt(total)  display “do want end program? (enter no process new order)” input endprogram end while  end module  module declarevariables(string ref endprogram, string ref endorder, real ref totalburger, real ref totalfry, real ref totalsoda, real ref  total, real ref tax, real ref subtotal, real ref option, real ref burgercount, real ref frycount, real ref sodacount) declare string endprogram = “no” declare string endorder = “no” declare real totalburger = 0 declare real totalfry = 0 declare real totalsoda = 0 declare real total = 0 declare real tax = 0 declare real subtotal = 0 declare integer option = 0 declare integer burgercount = 0 declare integer frycount = 0 declare integer sodacount = 0 end module  module resetvariables (real ref totalburger, real ref totalfry, real ref totalsoda, real ref total, real ref tax, real ref subtotal)  //reset variables totalburger = 0 totalfry = 0 totalsoda = 0 total = 0 tax = 0 subtotal = 0 end module  module getburger(real ref totalburger, integer burgercount) display “enter number of burgers want” input burgercount    set totalburger = totalburger + burgercount * .99 end module  module getfry(real ref totalfry, integer frycount) display “enter number of fries want” input frycount   set totalfry = totalfry + frycount * .79 end module  module getsoda(real ref totalsoda, integer sodacount) display “enter number of sodas want” input sodacount  set totalsoda = totalsoda + sodacount * 1.09 end module  module calctotal(real totalburger, real totalfry, real totalsoda, real ref total, real subtotal, real tax) set subtotal = totalburger + totalfry + totalsoda set tax = subtotal * .06 set total = subtotal + tax end module  module printreceipt(real total) display “your total $”, total end module 

here python code have far (python 2.7):

def main():      declarevariables(endprogram, endorder, totalburger, totalfry, totalsoda, total, tax, subtotal, option, burgercount, frycount, sodacount)      ##loop run program again     while endprogram == "no":         resetvariables(totalburger, totalfry, totalsoda, total, tax, subtotal)           ##loop take in order         while endorder == "no":             print "enter 1 yum yum burger"             print "enter 2 grease yum fries"             print "enter 3 soda yum"             option = input("enter now: ")             if option == 1:                 getburger(totalburger, burgercount)             elif option == 2:                 getfry(totalfry, frycount)             elif option == 3:                 getsoda(totalsoda, sodacount)             endorder = raw_input ("do want end order? (enter no add more items): ")         calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax)         printreceipt(total)          endprogram = raw_input("do want end program? (enter no process new order)")  def declarevariables(endprogram, endorder, totalburger, totalfry, totalsoda, total, tax, subtotal, option, burgercount, frycount, sodacount):     endprogram = "no"     endorder = "no"     totalburger = 0     totalfry = 0     totalsoda = 0     total = 0     tax = 0     subtotal = 0     option = 0     burgercount = 0     frycount = 0     sodacount = 0  def resetvariables(totalburger, totalfry, totalsoda, total, tax, subtotal):     totalburger = 0     totalfry = 0     totalsoda = 0     total = 0     tax = 0     subtotal = 0    def getburger(totalburger, burgercount):     burgercount = input ("enter number of burgers want: ")     totalburger = totalburger + burgercount *.99     return totalburger   def getfry(totalfry, frycount):     frycount = input ("enter number of fries want: ")     totalfry = totalfry + frycount * .79     return totalfry   def getsoda(totalsoda, sodacount):     sodacount = input ("enter number of sodas want: ")     totalsoda = totalsoda + sodacount * 1.09     return totalsoda   def calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax):     subtotal = totalburger + totalfry + totalsoda     tax = subtotal * .06     total = subtotal + tax     return total   def printreceipt(total):     print "your total $", total  main() 

these issues can not figure out how work past:

  1. local variable endprogram referenced before assignment. first time have seen variable initialization called module. module called @ beginning looks should initialized. missing this?
  2. if comment out declarevariable modules , create globals manual assignments, code run, returns receipt total of $0, if parameters aren't being passed reference. not sure how make accept reference in module.

can please assist pointing me in right direction? feel close , overlooking simple.

note: did search on google , forums, , have found exact problem in other locations. however, professor has constructed pseudocode instead of allowing in example. think have solved bit differently, python code must match professors pseudo me receive credit.

thank assistance can offer.

edit: thank pointers. changed code following, still getting $0 receipt totals when run edited code. direction on part of it?

def main():      endprogram = "no"     endorder = "no"     totalburger = 0     totalfry = 0     totalsoda = 0     total = 0     tax = 0     subtotal = 0     option = 0     burgercount = 0     frycount = 0     sodacount = 0      ##loop run program again     while endprogram == "no":           ##loop take in order         while endorder == "no":             print "enter 1 yum yum burger"             print "enter 2 grease yum fries"             print "enter 3 soda yum"             option = input("enter now: ")             if option == 1:                 getburger(totalburger, burgercount)             elif option == 2:                 getfry(totalfry, frycount)             elif option == 3:                 getsoda(totalsoda, sodacount)             endorder = raw_input ("do want end order? (enter no add more items): ")         calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax)         printreceipt(total)          endprogram = raw_input("do want end program? (enter no process new order)")    def getburger(totalburger, burgercount):     burgercount = input ("enter number of burgers want: ")     totalburger = totalburger + burgercount *.99     return totalburger   def getfry(totalfry, frycount):     frycount = input ("enter number of fries want: ")     totalfry = totalfry + frycount * .79     return totalfry   def getsoda(totalsoda, sodacount):     sodacount = input ("enter number of sodas want: ")     totalsoda = totalsoda + sodacount * 1.09     return totalsoda   def calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax):     subtotal = totalburger + totalfry + totalsoda     tax = subtotal * .06     total = subtotal + tax     return total   def printreceipt(total):     print "your total $", total  main() 

final edit:

in case else interested, how instructed complete assignment per professor. thank help.

def main():      ## initialize variables      endprogram, endorder, totalburger, totalfry, totalsoda, total, tax, subtotal, option, burgercount, frycount, sodacount = declarevariables()       ##loop run program again     while endprogram == "no":          #reset variables         endorder, totalburger, totalfry, totalsoda, total, tax, subtotal = resetvariables()          ##loop take in order         while endorder == "no":             print "enter 1 yum yum burger"             print "enter 2 grease yum fries"             print "enter 3 soda yum"             option = input("enter now: ")             if option == 1:                 totalburger = getburger(totalburger, burgercount)             elif option == 2:                 totalfry = getfry(totalfry, frycount)             elif option == 3:                 totalsoda = getsoda(totalsoda, sodacount)             endorder = raw_input ("do want end order? (enter no add more items): ")         total = calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax)         printreceipt(total)         endprogram = raw_input("do want end program? (enter no process new order)")   ## calculate total cost of burgers , return totalburger def getburger(totalburger, burgercount):     burgercount = input ("enter number of burgers want: ")     totalburger = totalburger + ( burgercount *.99 )     return totalburger  ## calculate total cost of fries , return totalfry def getfry(totalfry, frycount):     frycount = input ("enter number of fries want: ")     totalfry = totalfry + ( frycount * .79 )     return totalfry  ## calculate total cost of soda , return totalsoda def getsoda(totalsoda, sodacount):     sodacount = input ("enter number of sodas want: ")     totalsoda = totalsoda + ( sodacount * 1.09 )     return totalsoda  ## calculate total cost of burgers, fries, & soda. add tax , returns total.  def calctotal(totalburger, totalfry, totalsoda, total, subtotal, tax):     subtotal = totalburger + totalfry + totalsoda     tax = subtotal * .06     total = subtotal + tax     return total  ## print receipt total cost. def printreceipt(total):     print "your total $", total  ## initialize of variables , return of them def declarevariables():       endprogram = "no"      endorder = "no"      totalburger = 0      totalfry = 0      totalsoda = 0      total = 0      tax = 0      subtotal = 0      option = 0      burgercount = 0      frycount = 0      sodacount = 0       return endprogram, endorder, totalburger, totalfry, totalsoda, total, tax, subtotal, option, burgercount, frycount, sodacount  ## reset variables when order ends program continues start new order. ## return of reset variables def resetvariables():      endorder = "no"     totalburger = 0     totalfry = 0     totalsoda = 0     total = 0     tax = 0     subtotal = 0      return endorder, totalburger, totalfry, totalsoda, total, tax, subtotal   main() 

1. declare functions/variables intend use before use them.

put definitions of methods before main call them. example, main doesn't know function declarevariables while executes, hence, exception.

2. global variables or return variables

variables reference doesn't work c/++. might want @ this. can either return variables you've changed or declare them global (which might easiest). can find more info here

a side note, variables don't hold data more labels. a = b copying labels same object. can try out yourself:

>>a = [1,2,3] >>b =  # isn't copying values, labels >>b.append(100)  # changing value of 'b' change underlying object, thereby changing referenced objects >>print [1, 2, 3, 100] 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -