Python Forum
Unit 18 Procedural Programming Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit 18 Procedural Programming Python
#1
import random         #this is to import the random number for calculations
initialBalance = 10000  #this is the initial balance £1000
wholeSalePrice = 40    #this is the wholesale price
shopSalePrice = 80    #shops sells the product for £40
days = 0                #days end at 0 
newBalance = 250

#procedures

import random

initialBalance = 10000
randomNumber = random.randint(1,50)

def costs (wholeSalePrice,productPurchased):
    calculations = wholeSalePrice*productPurchased #this is to calculte the wholeslae price by the product purchased price
    print (calculations)
    return calculations

def calcNewBalance (initialBalance,addvertCost,productPurchased):  #this is to pass the calculations throgh the parameter
    answer = initialBalance-addvertCost-productPurchased*wholeSalePrice      #this is to output the new balnace after deducting the advertising cost and the product purchased cost from the new balnace  
    print (answer)
    return answer

def calpriceOfProduct (amount):
    priceOfProduct = amount #this is to calculte the wholeslae price by the product purchased price
    print (priceOfProduct)
    return priceOfProduct

def calshopPrice (amount):
    shopPrice = amount #this is to calculte the wholeslae price by the product purchased price
    print (shopPrice)
    return shopPrice

def calculateSalesFigures(salesFigures): #this is to generate a number to calculate sales on a daily basis
    sales = random.randint(1,50)
    print (sales)
    
    return sales

def expenses(everyDayExpenses): #this is to calculate the daily expenses 
    WholeSalePrice = 10
    stock = 20
    dailyExpenses = WholeSalePrice*stock    
    print (dailyExpenses)
    return dailyExpenses

def balanceUpdate(newBalance,salesFigure,dailyExpenses):
    updatedBalance = (newBalance + salesFigure - dailyExpenses)#this is the remaining balance after the daily expenses 
    print ("newbalance is £:" + str(updatedBalance))
    print (updatedBalance)
    return updatedBalance

#_________________________________________________________________________

#input

print("initial balance is £" + str (initialBalance))

advertisingCost = int(input("please enter a value for addvertcost £"))    #this inforamtion will be displayed for the user to insert the amount
productPurchased = int (input ("please enter the amount of products you wish to purchase for stock £"))  #this inforamtion will be displayed for the user to insert the amount
expenses = int(input("Please enter how much you want to spend on expenses £"))
priceOfProduct = int(input(" what is the price Of Product £"))
shopPrice = int(input(" what is the shopPrice £"))
sales = int(input(" what is the sales price £"))
print ("")

#_________________________________________________________________________
                        
#process

days = 30
randomNumber = random.randint(1,advertisingCost)
days = days - 1

while (days >0): and (newBalance >0): 
    if product purchased>0
    sales = random*advertisingCost
    productPurchased sold = sales//shopPrice
    
    print ("days" + str (days))   #this is the while statement for the loop
    
    
    if (productSold>productSold):
        lackOfStock = productSold - productPurchased
        lostProfit = lackOfStock*shopPrice#this is a block of code for If statement showing working out for handling products sold and in stock 
        sales = sales - lostProfit
        newBalance = newBalance-sales-expenses

         
        print ("newbalance is £:" + str(newBalance))
        print ("")
#_________________________________________________________________________
        
#output    

    if (newBalance <0): 
        print ("we need more stock")
    else:

        print("stock is fine") #this IF statement is to decide if the stock is okay or more stock is needed 



#costs = (wholeSalePrice,productPurchased) #these are the variables set for procedures 
#newBalance = calcNewBalance(newBalance,advertisingCost,productPurchased)
#salesFigure = calculateSalesFigures(0) 
#updatedBalances = balanceUpdate(newBalance,salesFigure,expenses)
Error:
invalid syntax
Reply
#2
On line 76 you have an extra colon. Remove the first one on the line.

How are you running your code? Any decent way of running it should tell you exactly what line, and often at what character on that line, the problem is occurring.
Reply
#3
import random         #this is to import the random number for calculations
initialBalance = 10000  #this is the initial balance £1000
wholeSalePrice = 40    #this is the wholesale price
shopSalePrice = 80    #shops sells the product for £40
days = 0                #days end at 0 
newBalance = 250

#procedures

import random

initialBalance = 10000
randomNumber = random.randint(1,50)

def costs (wholeSalePrice,productPurchased):
    calculations = wholeSalePrice*productPurchased #this is to calculte the wholeslae price by the product purchased price
    print (calculations)
    return calculations

def calcNewBalance (initialBalance,addvertCost,productPurchased):  #this is to pass the calculations throgh the parameter
    answer = initialBalance-addvertCost-productPurchased*wholeSalePrice      #this is to output the new balnace after deducting the advertising cost and the product purchased cost from the new balnace  
    print (answer)
    return answer

def calpriceOfProduct (amount):
    priceOfProduct = amount #this is to calculte the wholeslae price by the product purchased price
    print (priceOfProduct)
    return priceOfProduct

def calshopPrice (amount):
    shopPrice = amount #this is to calculte the wholeslae price by the product purchased price
    print (shopPrice)
    return shopPrice

def calculateSalesFigures(salesFigures): #this is to generate a number to calculate sales on a daily basis
    sales = random.randint(1,50)
    print (sales)
    
    return sales

def expenses(everyDayExpenses): #this is to calculate the daily expenses 
    WholeSalePrice = 40
    stock = 20
    dailyExpenses = WholeSalePrice*stock    
    print (dailyExpenses)
    return dailyExpenses

def balanceUpdate(newBalance,salesFigure,dailyExpenses):
    updatedBalance = (newBalance + salesFigure - dailyExpenses)#this is the remaining balance after the daily expenses 
    print ("newbalance is £:" + str(updatedBalance))
    print (updatedBalance)
    return updatedBalance

#_________________________________________________________________________

#input

print("initial balance is £" + str (initialBalance))

advertisingCost = int(input("please enter a value for advertingCost £"))    #this inforamtion will be displayed for the user to insert the amount
productPurchased = int (input ("please enter the amount of products you wish to purchase for stock £"))  #this inforamtion will be displayed for the user to insert the amount
expenses = int(input("Please enter how much you want to spend on expenses £"))
priceOfProduct = int(input(" what is the price Of Product £"))
shopPrice = int(input(" what is the shopPrice £"))
sales = int(input(" what is the sales price £"))
print ("")

#_________________________________________________________________________
                        
#process

days = 30
randomNumber = random.randint(1,advertisingCost)
days = days - 1

while (days >0) and (newBalance >0): 
    if productPurchased>0:
        sales = (random.randint*advertisingCost)
        productSold = sales//shopPrice
    
    print ("days" + str (days))   #this is the while statement for the loop
    
    
    if (productSold>productSold):
        lackOfStock = productSold - productPurchased
        lostProfit = lackOfStock*shopPrice#this is a block of code for If statement showing working out for handling products sold and in stock 
        sales = sales - lostProfit
        newBalance = newBalance-sales-expenses

         
        print ("newbalance is £:" + str(newBalance))
        print ("")
#_________________________________________________________________________
        
#output    

    if (newBalance <0): 
        print ("we need more stock")
    else:

        print("stock is fine") #this IF statement is to decide if the stock is okay or more stock is needed 



costs = (wholeSalePrice,productPurchased) #these are the variables set for procedures 
newBalance = calcNewBalance(newBalance,advertisingCost,productPurchased)
salesFigure = calculateSalesFigures(0) 
updatedBalances = balanceUpdate(newBalance,salesFigure,expenses)
Error:
initial balance is £10000 please enter a value for advertingCost £40 please enter the amount of products you wish to purchase for stock £20 Please enter how much you want to spend on expenses £20 what is the price Of Product £10 what is the shopPrice £15 what is the sales price £12 Traceback (most recent call last): File "F:/Level 4/Kevin/Assignement_testing.py", line 78, in <module> sales = (random.randint*advertisingCost) TypeError: unsupported operand type(s) for *: 'method' and 'int' >>>
Reply
#4
You need parenthesis to call the function. What you're trying to do is multiply a function by an int. You want to multiply the result of the function call with an int.
random.randint -> random.randint()
Reply
#5
1) You are going to have a infinite loop. Need to move days = days - 1 inside the while loop.
2) .randint need to have input argument as well. .randint(a, b)
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework Python unit test Paragoon2 4 1,475 Dec-12-2022, 12:45 PM
Last Post: Paragoon2
  Help with Unit Tests pdub787 3 3,010 Nov-20-2019, 07:45 PM
Last Post: ndc85430
  Verilog HDL Programming to Python Programming? noobcoder 1 2,984 Jul-18-2019, 09:28 PM
Last Post: nilamo
  unit 18 codes Miss_Kaur 7 4,972 Dec-19-2017, 02:49 PM
Last Post: sparkz_alot
  Unit 18: Procedural Programming Assignment (Shop Simulation) shaheduk323 28 13,147 Dec-17-2017, 08:31 PM
Last Post: Terafy
  Unit 18 Procedural Programming Python kanwal121 6 3,993 Dec-17-2017, 07:18 PM
Last Post: Terafy

Forum Jump:

User Panel Messages

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