![]() |
Unit 18: Procedural Programming Assignment (Shop Simulation) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Unit 18: Procedural Programming Assignment (Shop Simulation) (/thread-6992.html) |
RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - shaheduk323 - Dec-16-2017 (Dec-16-2017, 10:21 PM)j.crater Wrote: You returned the function, not the value (of variable) which the function calculated (advertisingcost vs. advertcost, big difference!) Thanks so much finally i got rid of this stupid programming mistake. Ahh i am so tired all day i been working on this stupid thing only to find i been making the same mistake 100 times. ![]() New error i already have newbalance but still it shows not defined initialbalance = 500 wholesale = 20 shopsale = 35 import random # "Procedures used in the program" def balance(): print ("the initial balance is £ " +str(totalmoney)) return balance def numofproduct(): productname = int(input("How many product items do you wish to purchase? ")) return productname def newbalances(initialbalance, productname, advertisingcost): newbalance = initialbalance - advertisingcost - ptoductname * wholesaleprice return newbalance def advertisingcost(): advertcost = int(input("How much do you want to spend on advertising cost in £? ")) return advertcost def randmnum(): randmnum = random.randint(1,100) # "30 Days Simulation loop" day = 0 while day<30: day = day+1 print("day", + (day)) randmnum = random.randint(1,100) figuresales = (randmnum * advertisingcost()) print ("The figure sales is £" +str (figuresales)) if newbalance<0: print ("Stock has finished. Simulation ended") else: print ("stock is good and running")
RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - j.crater - Dec-17-2017 Well, the error message pretty much said it all. What is newbalance supposed to be when it is compared to 0? RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - shaheduk323 - Dec-17-2017 I still do not understand what to put in the newbalance. i already have newbalance defined. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - j.crater - Dec-17-2017 In line 48, where error happens: if newbalance<0:What is the value of newbalance here? How is it defined? Error message says it is not defined, so it is not =) The only time newbalance is mentioned is some lines earlier, within a function definition. What was your purpose when defining that function? I suggest you to also use print in cases like this, so you can follow variables and there values when they seem to cause errors. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - shaheduk323 - Dec-17-2017 i am trying to follow this If the shop runs out of stock before the end of the 30 days, they cannot make any more sales until the 30 days are over and more stock is purchased. If the balance goes below zero, the simulation ends. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - j.crater - Dec-17-2017 You are following the instructions fine, but you have logical errors in the program. I am trying to have you spot the errors yourself and learn from that. Read the code as if the program was running, and (for now) foucs on newbalance variable. What is happening with it? Where/when does it get defined? Another thing, the simulation will not end when stock gets below 0, because you don't exit the while loop at that point, it will just continue with next iteration until day hits 30. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - shaheduk323 - Dec-17-2017 (Dec-17-2017, 12:39 PM)j.crater Wrote: You are following the instructions fine, but you have logical errors in the program. I am trying to have you spot the errors yourself and learn from that. it is already defined on line 19 RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - j.crater - Dec-17-2017 It is not defined there, on line 19 it gets returned from function. Which means you first need to call the function, to get the value. These are very basic concepts. I would suggest you to study some basic Python learning material. You can find some tutorials on our forums, as well as countless resources elsewhere online. Your learning would be much more efficient that way, and it would save you a looot of time when tackling tasks like the one you have now. Seriously, try it. Invest an hour or two in following some Python basics tutorial (especially topics such as variables and functions), and then return to this task. It will become very simple. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - Terafy - Dec-17-2017 In plain English... you defined the function: def newbalances(initialbalance, productname, advertisingcost): ...But you didn't called the function: someVariableName = newbalances(arg0,arg1,arg2)P.S. Please don't stress the polar bear. They're already stress enough about global warming. RE: Unit 18: Procedural Programming Assignment (Shop Simulation) - shaheduk323 - Dec-17-2017 (Dec-17-2017, 01:48 PM)Terafy Wrote: In plain English... you defined the function: thats even worse now i am confused. |