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)
#1
Unit 18: Procedural Programming Assignment (Shop Simulation)

Specification

The company are involved in several innovative projects and are currently in the process of obtaining a contract for a game that simulates the financial running of a shop that sells a single product.

What you have been asked to do is develop and implement a prototype that demonstrates the basic principle of such a game using the process detailed below:

Step 1:

The user is presented with an initial balance.

Step 2:

The user enters how much they want to spend on advertising their product (as this is a prototype, the shop only sells one item), and how many product items they wish to purchase for their stock.

A new balance is calculated based on the number of product items purchased and how much has been spent on advertising.

The wholesale purchase price and the shop’s sales price of the product should be set as constants in the program.

Step 3:

The simulation then runs for 30 days. Each day, a random number must be generated to calculate sales figures by multiplying the random number with how much has been spent on advertising.

A new balance is calculated based on sales with a deduction of daily expenses. Each day (one second) data for stock, sales, balance and the day number are displayed to the user.

Step 4:

Step 2 is repeated until the program is closed.

Other Information:

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.

My Code

initialbalance = 500
wholesale = 20


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 numofproduct


def newbalance():
newbalance = initialbalance - (productname * advertcost)
return newbalance


def advertisingcost():
advertcost = int(input("How much do you want to spend on advertising cost in £? "))

def randmnum():
randmnum = random.randint(1,100)



# "30 Days Simulation loop"


days = 0

while days <30:
days = days +1
print("days", + (days))



randmnum = random.randint(1,100)
figuresales = (randmnum * advertisingcost)
print ("The figure sales is £" +str (figuresales))












Error!!

Traceback (most recent call last):
File "C:\Users\Shahed\Desktop\Python\Portable Python 3.2.1.1\assignment python.py", line 42, in <module>
figuresales = (randmnum * advertisingcost)
TypeError: unsupported operand type(s) for *: 'int' and 'function'
>>>

I do not understand what the error means and cannot find a way to fix this
Reply
#2
Hi, please edit your post so that code is put in Python code tags and error message in error code tags. You can find help here.
Reply
#3
initialbalance = 500
wholesale = 20


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 numofproduct


def newbalance():
    newbalance = initialbalance - (productname * advertcost)
    return newbalance


def advertisingcost():
    advertcost = int(input("How much do you want to spend on advertising cost in £? "))

def randmnum():
    randmnum = random.randint(1,100)



# "30 Days Simulation loop"


days = 0

while days <30:
    days = days +1
    print("days", + (days))



    randmnum = random.randint(1,100)
    figuresales = (randmnum * advertisingcost)
    print  ("The figure sales is £" +str (figuresales))
Error:
Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> days 1 Traceback (most recent call last): File "C:\Users\Shahed\Desktop\Python\Portable Python 3.2.1.1\assignment python.py", line 42, in <module> figuresales = (randmnum * advertisingcost) TypeError: unsupported operand type(s) for *: 'int' and 'function' >>>
Reply
#4
Nice job with code tags.
Problem is that randnum is an integer variable, but advertisingcost (without parentheses!!!) is a function object. So error message simply tells you that you can't multiply integer and a function (you don't say?! :P).
What you probably want instead of advertisingcost is the value that the function returns. For that, you will need to call that function (function name with parenthses) and modify that function, so it returns the value you want to include in calculation. I see you did that in your other functions.
Reply
#5
Quote:What you probably want instead of advertisingcost is the value that function returns. For that, you will need to call that function (function name with parenthses) and modify that function, so it returns the value you want to include in calculation.

i dont understand still. what can i modify this into
Reply
#6
Modify the function so it will return a value. That way when you will be able to multiply randnum with another number - the one your function (advertisingcost) returns.
Reply
#7
Quote:Modify the function so it will return a value. That way when you will be able to multiply randnum with another number - the one your function (advertisingcost) returns.

i cannot get it to return a value because this is from the users input of the (advertising cost) on line 22 & 23

Error:
Traceback (most recent call last): File "C:\Users\Shahed\Desktop\Python\Portable Python 3.2.1.1\assignment python.py", line 43, in <module> figuresales = (randmnum * advertisingcost()) TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' >>>
Reply
#8
User inputs a value, that is stored into a variable. And you can return the value of that variable from a function, as you did in other functions.
Reply
#9
(Dec-16-2017, 08:36 PM)j.crater Wrote: User inputs a value, that is stored into a variable. And you can return the value of that variable from a function, as you did in other functions.
i did that and it still shows the same error. i did return advertising cost

def newbalance():
    newbalance = initialbalance - (productname * advertcost)
    return newbalance


def advertisingcost():
    advertcost = int(input("How much do you want to spend on advertising cost in £? "))
    return advertisingcost

def randmnum():
    randmnum = random.randint(1,100)

    


# "30 Days Simulation loop"


days = 0

while days <30:
    days = days +1
    print("days", + (days))



    randmnum = random.randint(1,100)
    figuresales = (randmnum * advertisingcost())
    print  ("The figure sales is £" +str (figuresales))



still the same error

Error:
days 1 How much do you want to spend on advertising cost in £? 55 Traceback (most recent call last): File "C:\Users\Shahed\Desktop\Python\Portable Python 3.2.1.1\assignment python.py", line 44, in <module> figuresales = (randmnum * advertisingcost() ) TypeError: unsupported operand type(s) for *: 'int' and 'function' >>>
Reply
#10
You returned the function, not the value (of variable) which the function calculated (advertisingcost vs. advertcost, big difference!)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework Python unit test Paragoon2 4 1,515 Dec-12-2022, 12:45 PM
Last Post: Paragoon2
  Simulation DaRTHYGT 2 2,723 Jan-27-2020, 10:09 PM
Last Post: micseydel
  Help with Unit Tests pdub787 3 3,049 Nov-20-2019, 07:45 PM
Last Post: ndc85430
  Verilog HDL Programming to Python Programming? noobcoder 1 3,026 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Help for my assignment - Object Oriented Programming denizkb 5 5,078 Jan-05-2019, 06:43 PM
Last Post: stullis
  Unit 18 Procedural Programming Python kanwal121 4 3,944 Dec-21-2017, 10:53 PM
Last Post: Terafy
  unit 18 codes Miss_Kaur 7 5,011 Dec-19-2017, 02:49 PM
Last Post: sparkz_alot
  Unit 18 Procedural Programming Python kanwal121 6 4,063 Dec-17-2017, 07:18 PM
Last Post: Terafy
  programming assignment mario 2 3,456 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