I started learning python a couple of days ago from tutorials and some documentation. Haven't really practiced more then 2 hours on it.
My bro employed a new worker a few days ago, as a result of that he needs to count money at the start of day and end of day to see if everything is OK. I wrote a simple program to help him do that, it's nothing really but i was wondering if there's a simpler way to write it.
I will post the code here:
x1 = 5.5
x2 = 8
x3 = 13.5
coins = input("Coins at start of day: ")
cash = input("Cash at start of day: ")
startmoney = coins + cash
x1s = input("Product X1 sold: ")
x1sold = x1s * x1
x2s = input("Product X2 sold: ")
x2sold = x2s * x2
x3s = input("Product X3 sold ")
x3sold = x3s * x3
total_sales = x1sold + x2sold + x3sold
print "Total sales: "
print total_sales
total_money = total_sales + startmoney
print "Cash should be: "
print total_money
coins_end = input("Coins at the end of day: ")
cash_end = input("Cash at the end of day: ")
endmoney = coins_end + cash_end
print endmoney
Result = endmoney - total_money
print "At the end of the day: "
print Result
raw_input("Press<enter>")
To explain a few things:
Coins - That is spare money or change, i couldn't think of a more appropriate word in english as i translated the code from my native language so that people here can better understand the program.
Cash - well it's cash, paper money.
Startmoney - it's a total of coins and cash that the employee is given at the start of the day.
x1, x2, x3 - are products. They only sell 3 products so i named them like that to be simpler. In the original code every product has it's name.
total_sales - is the total sales made for that day.
total_money - is all the money that SHOULD be in the shop.
end_money - refers to the coins and cash that is found in the store at the end of the day.
I am just curious if i could've written it simpler but since i am a total beginner to python and programming in general(had a couple of days learning of Java a few years back) i couldn't think of a better way to write but i just feel that there's a much simpler way to do it.
Cheers


Sign In
Create Account

Back to top









