Python Forum
Unit 18: Procedural Programming Assignment (Shop Simulation)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit 18: Procedural Programming Assignment (Shop Simulation)
#11
(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. Big Grin

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")
Error:
day 1 How much do you want to spend on advertising cost in £? 55 The figure sales is £4620 Traceback (most recent call last): File "C:\Users\Shahed\Desktop\Python\Portable Python 3.2.1.1\assignment python.py", line 48, in <module> if newbalance<0: NameError: name 'newbalance' is not defined >>>
Reply
#12
Well, the error message pretty much said it all. What is newbalance supposed to be when it is compared to 0?
Reply
#13
I still do not understand what to put in the newbalance. i already have newbalance defined.
Reply
#14
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.
Reply
#15
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.
Reply
#16
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.
Reply
#17
(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.
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?

it is already defined on line 19
Reply
#18
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.
Reply
#19
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.
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#20
(Dec-17-2017, 01:48 PM)Terafy Wrote: In plain English... you defined the function:

def newbalances(initialbalance, productname, advertisingcost):
    ...[python]

But you didn't called the function:

[python]someVariableName = newbalances(arg0,arg1,arg2)
P.S. Please don't stress the polar bear. They're already stress enough about global warming.

thats even worse now i am confused.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework Python unit test Paragoon2 4 1,510 Dec-12-2022, 12:45 PM
Last Post: Paragoon2
  Simulation DaRTHYGT 2 2,720 Jan-27-2020, 10:09 PM
Last Post: micseydel
  Help with Unit Tests pdub787 3 3,039 Nov-20-2019, 07:45 PM
Last Post: ndc85430
  Verilog HDL Programming to Python Programming? noobcoder 1 3,015 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Help for my assignment - Object Oriented Programming denizkb 5 5,060 Jan-05-2019, 06:43 PM
Last Post: stullis
  Unit 18 Procedural Programming Python kanwal121 4 3,940 Dec-21-2017, 10:53 PM
Last Post: Terafy
  unit 18 codes Miss_Kaur 7 5,009 Dec-19-2017, 02:49 PM
Last Post: sparkz_alot
  Unit 18 Procedural Programming Python kanwal121 6 4,054 Dec-17-2017, 07:18 PM
Last Post: Terafy
  programming assignment mario 2 3,450 Dec-16-2017, 06:28 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020