Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unit 18 codes
#1
import random
initialbalance = 1000
Wholesaleprice = 100
ShopSalesprice = 200
Days = 0

# user enters the initial balance 
def initialbalance():
    initialbalance = int(input("Your initialbalance for shop simulation £"))
    return initialbalance

# user enters the amount he/she wants to spend on promoting products
def productadvertising():
    global advertisingcost
    advertisingcost= int(input("please enter how much money you want to spend for advertising £?"))
    print (advertisingcost)
    return advertisingcost

#user enters how much items willing to purchase 
def Purchaseditems():
    Purchaseditems = int(input("please enter the number of purchased items?"))
    print (Purchaseditems)
    return Purchaseditems

# calculate Wholesaleprice of purchasedproducts
def Wholesalecost(boughtproducts):
    cost = Wholesaleprice*boughtproducts
    print (str(Wholesaleprice)+str(boughtproducts))
    return cost

# figure out the balance1 after doem the advertising and purchasedproducts. this will give you the new balance after spent mny on promotions and purchasing  
def Newbalance1(bal,boughtproducts):

    balance1 = advertisingcost * boughtproducts
    balance1 = bal- advertisingcost-boughtproducts # initialbalance-advertisingcost-purchsedproducts
    print (balance1)
    return balance1

# figure out the total sales, random number will be used to multiply by advertisingcost in order to figure out the  total sales
def Salesfigure():
    global Salesfigure
    Salesfigure = random.randint(1,40)*advertisingcost
    print("The sales for one day are £" + str(Salesfigure))
    
# user enters the dailyexpenses    
def Dailyexpenses():
    global expenses
    expenses = int(input("please enter a value for your daily expenses £"))
    print (expenses)

# while loop and if statemnts  
def loop (Days,bal1,Promotion,boughtproducts,Sales,dailycost):
    while (Days <30):
        Days = Days + 1
        print("Day ",+ str(Days))
        print(Sales)
        
# figure out the potentialsales

        Salesfigure = Sales* Promotion
        potentialProductSold = Salesfigure//ShopSalesprice
        print (potentialProductSold)
        
# this is the calculations of Newbalance2 (initialbalance - Salesfigure- Dailyexpenses)
        Newbalance2 = bal-Sales- dailycost
        print ("your Newbalance is £" +  str (Newbalance2))
 #       
    if (potentialProductSold<boughtproducts):
        instock = poentialProductSold-boughtproducts
        profit = Sales-boughtproducts
        result =("the numbr of products are available in stock" + str(profit)) 

        print(" profit")
    else:
        print ("no profit")

 # while (Days<30) and (bal1<0):
# if days less than 30 stock runs out otherwise there is enough stock 

    if (Days<30):
        print ("shop is running out of stock and cannot make more sales")
    else:
        print ("shop has enough stock to sell")
        
#if initial balance is less than 0 simulation ends otherwise continue 
    if (bal1<0):
        print ("simulation finished")
        
    else :
        print ("simulation continue")
        
#this is if user gives his/her consent by saying Y (yes) simulation continues otherwise ends the simulation
# cont means continue
    cont==true
    while (cont== true):
        User_Consent = int(input("Are you willing to continue the shop simulation?"))

    if (User_Consent == Y):
            print ("continue")
    else:
            print("end")

                    
print(loop)
       

bal=initialbalance()
Promotion=productadvertising()
boughtproducts=Purchaseditems()
Wholesalecost(boughtproducts)
bal1=Newbalance1(bal,boughtproducts)
Sales=Salesfigure()
dailycost=Dailyexpenses()
loop=(Days,bal1,Promotion,boughtproducts,Sales,dailycost)
Error:
[/python]
Reply
#2
No error? @Miss_Kaur that is a bit weird. you need to send the error code too
Reply
#3
import random
initialbalance = 1000
Wholesaleprice = 100
ShopSalesprice = 200
Days = 0
 
# user enters the initial balance
def initialbalance():
    initialbalance = int(input("Your initialbalance for shop simulation £"))
    return initialbalance
 
# user enters the amount he/she wants to spend on promoting products
def productadvertising():
    global advertisingcost
    advertisingcost= int(input("please enter how much money you want to spend for advertising £?"))
    print (advertisingcost)
    return advertisingcost
 
#user enters how much items willing to purchase
def Purchaseditems():
    Purchaseditems = int(input("please enter the number of purchased items?"))
    print (Purchaseditems)
    return Purchaseditems
 
# calculate Wholesaleprice of purchasedproducts
def Wholesalecost(boughtproducts):
    cost = Wholesaleprice*boughtproducts
    print (str(Wholesaleprice)+str(boughtproducts))
    return cost
 
# figure out the balance1 after doem the advertising and purchasedproducts. this will give you the new balance after spent mny on promotions and purchasing  
def Newbalance1(bal,boughtproducts):
 
    balance1 = advertisingcost * boughtproducts
    balance1 = bal- advertisingcost-boughtproducts # initialbalance-advertisingcost-purchsedproducts
    print (balance1)
    return balance1
 
# figure out the total sales, random number will be used to multiply by advertisingcost in order to figure out the  total sales
def Salesfigure():
    global Salesfigure
    Salesfigure = random.randint(1,40)*advertisingcost
    print("The sales for one day are £" + str(Salesfigure))
     
# user enters the dailyexpenses    
def Dailyexpenses():
    global expenses
    expenses = int(input("please enter a value for your daily expenses £"))
    print (expenses)
 
# while loop and if statemnts  
def loop (Days,bal1,Promotion,boughtproducts,Sales,dailycost):
    while (Days <30):
        Days = Days + 1
        print("Day ",+ str(Days))
        print(Sales)
         
# figure out the potentialsales
 
        Salesfigure = Sales* Promotion
        potentialProductSold = Salesfigure//ShopSalesprice
        print (potentialProductSold)
         
# this is the calculations of Newbalance2 (initialbalance - Salesfigure- Dailyexpenses)
        Newbalance2 = bal-Sales- dailycost
        print ("your Newbalance is £" +  str (Newbalance2))
 #       
    if (potentialProductSold<boughtproducts):
        instock = poentialProductSold-boughtproducts
        profit = Sales-boughtproducts
        result =("the numbr of products are available in stock" + str(profit))
 
        print(" profit")
    else:
        print ("no profit")
 
 # while (Days<30) and (bal1<0):
# if days less than 30 stock runs out otherwise there is enough stock
 
    if (Days<30):
        print ("shop is running out of stock and cannot make more sales")
    else:
        print ("shop has enough stock to sell")
         
#if initial balance is less than 0 simulation ends otherwise continue
    if (bal1<0):
        print ("simulation finished")
         
    else :
        print ("simulation continue")
         
#this is if user gives his/her consent by saying Y (yes) simulation continues otherwise ends the simulation
# cont means continue
    cont==true
    while (cont== true):
        User_Consent = int(input("Are you willing to continue the shop simulation?"))
 
    if (User_Consent == Y):
            print ("continue")
    else:
            print("end")
 
                     
print(loop)
        
 
bal=initialbalance()
Promotion=productadvertising()
boughtproducts=Purchaseditems()
Wholesalecost(boughtproducts)
bal1=Newbalance1(bal,boughtproducts)
Sales=Salesfigure()
dailycost=Dailyexpenses()
loop=(Days,bal1,Promotion,boughtproducts,Sales,dailycost)
Output:
<function loop at 0x02E3F198> Your initialbalance for shop simulation £500 please enter how much money you want to spend for advertising £?100 100 please enter the number of purchased items?20 20 10020 380 The sales for one day are £1300 please enter a value for your daily expenses £10 10
Reply
#4
redit your thread and add error using the red cross button in quick reply. also enter the whole code
Reply
#5
Except that is not an error. You have a print(loop) in line 105. Loop is a function, so it prints the memory address (0x02E3F198). That's why you get <function loop at 0x02E3F198>.
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
Just to add to what @Terafy already said - loop is a function, but it does not return anything, just prints inside a loop body. So you don't want to print it (on line 105) but just call the loop. Otherwise your print statement will print None
Reply
#7
and can you describe to us, what output do you want to get?
Reply
#8
Isn't this the same code you posted in your previous thread? https://python-forum.io/Thread-unit-18-codes. Please do not create multiple threads regarding the same subject. It also appears you did not implement the suggestions made in your original post. I've merged the two Threads in order to avoid confusion.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
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
  Unit 18 Procedural Programming Python kanwal121 4 3,888 Dec-21-2017, 10:53 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