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
def newBalance(newBalance,addvertCost,productPurchased): #this is to pass the calculations throgh the parameter
answer = newBalance-addvertCost-productPurchased #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

Traceback (most recent call last):
File "F:\Level 4\Kevin\nadia.py", line 80, in <module>
NewBalance = newBalance(newBalance,addvertCost,productPurchased)
File "F:\Level 4\Kevin\nadia.py", line 16, in newBalance
answer = newBalance-addvertCost-productPurchased #this is to output the new balnace after deducting the advertising cost and the product purchased cost from the new balnace
TypeError: unsupported operand type(s) for -: 'function' and 'tuple'
>>>
Reply
#2
You defined the function:

def newbalances(initialbalance, productname, advertisingcost):
    ...
But you didn't called the function.

Example of calling a function:

someVariableName = newbalances(inputParameter0,inputParameter1,inputParameter3)
unfortunately we don't know your input parameters.
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#3
import random         #this is to import the random number for calculations
initialBalance = 1000  #this is the initial balance £1000
wholeSalePrice = 10    #this is the wholesale price
shopSalePrice = 40    #shops sells the product for £40
addvertCost = 1,20   #advertising cost is between the range of £1-£20
days = 0   

#procedures

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

def newBalance(newBalance,addvertCost,productPurchased):  #this is to pass the calculations throgh the parameter
    answer = newBalance-addvertCost-productPurchased      #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 calculateSalesFigures(salesFigures): #this is to generate a number to calculate sales on a daily basis
    sales = random.randit(1,50)
    print (sales)
    return sales

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

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



#input

itemPurchased = int(input("please enter the value for itempurchased £"))  #this inforamtion will be displayed for the user to insert the amount
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

print ("")

                        
#process

while days>0:
    days = days + 1
    print ("days" + str (days))   #this is the while statement for the loop
    
    randomNumber = random.randint(1,50)          
    salesFigure = (randomNumber*advertisingCost)
    print ("salesFigures is £:" +str(salesFigure)) #this block of code is to work out the sales figure by random number*advertising cost

    updatedBalances = (newBalance + salesFigure - dailyexpenses) #this is to display the newbalnce on the users screen
    print ("newbalance is £:" + str(updatedBalances))
    print ("")

    sold = salesFigure // priceOfProduct - shopPrice
    if (sold > shopPrice):
        lackOfStock = sold - stock
        costProfit = lackOfStock*priceOfProduct #this is a block of code for If statement showing working out for handling products sold and in stock 
        sales = sales - costProfit

        
#output    

    if newBalance >=0:
        print ("stock is fine ")
    else:

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



costs (wholeSalePrice,productPurchased) #these are thevariables set for procedures 
NewBalance = newBalance(newBalance,addvertCost,productPurchased)
SalesFigure = calculateSalesFigures() 
Expenses = expenses()
BalanceUpdate = balanceUpdate()
Error:
please enter the value for itempurchased £50 please enter a value for addvertcost £4 please enter the amount of products you wish to purchase for stock £6 60 Traceback (most recent call last): File "F:\Level 4\Kevin\nadia.py", line 80, in <module> NewBalance = newBalance(newBalance,addvertCost,productPurchased) File "F:\Level 4\Kevin\nadia.py", line 16, in newBalance answer = newBalance-addvertCost-productPurchased #this is to output the new balnace after deducting the advertising cost and the product purchased cost from the new balnace TypeError: unsupported operand type(s) for -: 'function' and 'tuple' >>>

I have added the = sign to call the function but now have another issue. I will post it in the forum. thank you

import random         #this is to import the random number for calculations
initialBalance = 1000  #this is the initial balance £1000
wholeSalePrice = 10    #this is the wholesale price
shopSalePrice = 40    #shops sells the product for £40
addvertCost = 1,20   #advertising cost is between the range of £1-£20
days = 0   

#procedures

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

def newBalance(newBalance,addvertCost,productPurchased):  #this is to pass the calculations throgh the parameter
    answer = newBalance-addvertCost-productPurchased      #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 calculateSalesFigures(salesFigures): #this is to generate a number to calculate sales on a daily basis
    sales = random.randit(1,50)
    print (sales)
    return sales

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

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



#input

itemPurchased = int(input("please enter the value for itempurchased £"))  #this inforamtion will be displayed for the user to insert the amount
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

print ("")

                        
#process

while days>0:
    days = days + 1
    print ("days" + str (days))   #this is the while statement for the loop
    
    randomNumber = random.randint(1,50)          
    salesFigure = (randomNumber*advertisingCost)
    print ("salesFigures is £:" +str(salesFigure)) #this block of code is to work out the sales figure by random number*advertising cost

    updatedBalances = (newBalance + salesFigure - dailyexpenses) #this is to display the newbalnce on the users screen
    print ("newbalance is £:" + str(updatedBalances))
    print ("")

    sold = salesFigure // priceOfProduct - shopPrice
    if (sold > shopPrice):
        lackOfStock = sold - stock
        costProfit = lackOfStock*priceOfProduct #this is a block of code for If statement showing working out for handling products sold and in stock 
        sales = sales - costProfit

        
#output    

    if newBalance >=0:
        print ("stock is fine ")
    else:

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



costs = (wholeSalePrice,productPurchased) #these are thevariables set for procedures 
NewestBalance = newBalance(newBalance,addvertCost,productPurchased)
SalesFigure = calculateSalesFigures() 
Expenses = expenses()
BalanceUpdate = balanceUpdate()
Error:
please enter the value for itempurchased £50 please enter a value for addvertcost £4 please enter the amount of products you wish to purchase for stock £6 Traceback (most recent call last): File "F:\Level 4\Kevin\nadia.py", line 80, in <module> NewestBalance = newBalance(newBalance,addvertCost,productPurchased) File "F:\Level 4\Kevin\nadia.py", line 16, in newBalance answer = newBalance-addvertCost-productPurchased #this is to output the new balnace after deducting the advertising cost and the product purchased cost from the new balnace TypeError: unsupported operand type(s) for -: 'function' and 'tuple' >>>
Reply
#4
@kanwal121
Please post your code in Python code tags and error message in error tags.
See help here.
Edit:
Thanks!
Reply
#5
You need a naming convention... you used newBalance as a function name and a variable... that's a no-no

while days>0:
    days = days + 1
that loop will never end. Because days will always be >0

updatedBalances = (newBalance + salesFigure - dailyexpenses) #this is to display the newbalnce on the users screen
there's no variable called newBalance or dailyexpenses from line 39 to 58. That why you have that error.

    sold = salesFigure // priceOfProduct - shopPrice
    if (sold > shopPrice):
        lackOfStock = sold - stock
        costProfit = lackOfStock*priceOfProduct #this is a block of code for If statement showing working out for handling products sold and in stock 
        sales = sales - costProfit
bunch of missing variables.

Anyways what j.crater was telling you before. The variable you define in your function are local variables. You can't grab the local variable and use in the main code or other function. You would need to create the variables again.
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#6
that loop will never end. Because days will always be >0
you have replied to the loop message. What calculations will end the loop please?
Reply
#7
I just read your code (I didn't run your code) and pointed what is potentially wrong with it. It you can give the missing information your code would work.
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,510 Dec-12-2022, 12:45 PM
Last Post: Paragoon2
  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,009 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Unit 18 Procedural Programming Python kanwal121 4 3,938 Dec-21-2017, 10:53 PM
Last Post: Terafy
  unit 18 codes Miss_Kaur 7 5,008 Dec-19-2017, 02:49 PM
Last Post: sparkz_alot
  Unit 18: Procedural Programming Assignment (Shop Simulation) shaheduk323 28 13,339 Dec-17-2017, 08:31 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