Dec-16-2017, 06:00 PM
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
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