Skip to content

Commit ca665f2

Browse files
Merge pull request #2659 from LAbhilashKumar/updated_billing
Updated billing
2 parents fbfcee6 + c09026a commit ca665f2

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

billing.py

+70-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1-
prices = [12.99, 5.49, 8.75]
2-
total = sum(prices)
3-
print(total)
1+
updated_billing
2+
items= {"apple":5,"soap":4,"soda":6,"pie":7,"cake":20}
3+
total_price=0
4+
try :
5+
print("""
6+
Press 1 for apple
7+
Press 2 for soap
8+
Press 3 for soda
9+
Press 4 for pie
10+
Press 5 for cake
11+
Press 6 for bill""")
12+
while True:
13+
choice = int(input("enter your choice here..\n"))
14+
if choice ==1:
15+
print("Apple added to the cart")
16+
total_price+=items["apple"]
17+
18+
elif choice== 2:
19+
print("soap added to the cart")
20+
total_price+= items["soap"]
21+
elif choice ==3:
22+
print("soda added to the cart")
23+
total_price+=items["soda"]
24+
elif choice ==4:
25+
print("pie added to the cart")
26+
total_price+=items["pie"]
27+
elif choice ==5:
28+
print("cake added to the cart")
29+
total_price+=items["cake"]
30+
elif choice == 6:
31+
print(f"""
32+
33+
Total amount :{total_price}
34+
""")
35+
break
36+
else:
37+
print("Please enter the digits within the range 1-6..")
38+
except:
39+
print("enter only digits")
40+
41+
"""
42+
Code Explanation:
43+
A dictionary named items is created to store product names and their corresponding prices.
44+
Example: "apple": 5 means apple costs 5 units.
45+
46+
one variable is initialized:
47+
48+
total_price to keep track of the overall bill.
49+
50+
51+
A menu is printed that shows the user what number to press for each item or to generate the final bill.
52+
53+
A while True loop is started, meaning it will keep running until the user explicitly chooses to stop (by selecting "6" for the bill).
54+
55+
Inside the loop:
56+
57+
The user is asked to enter a number (1–6).
58+
59+
Depending on their input:
60+
61+
If they enter 1–5, the corresponding item is "added to the cart" and its price is added to the total_price.
62+
63+
If they enter 6, the total price is printed and the loop breaks (ends).
64+
65+
If they enter something outside 1–6, a warning message is shown.
66+
67+
The try-except block is used to catch errors if the user enters something that's not a number (like a letter or symbol).
68+
In that case, it simply shows: "enter only digits".
69+
"""
70+

0 commit comments

Comments
 (0)