Skip to content

Updated billing #2659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions billing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
prices = [12.99, 5.49, 8.75]
total = sum(prices)
print(total)
updated_billing
items= {"apple":5,"soap":4,"soda":6,"pie":7,"cake":20}
total_price=0
try :
print("""
Press 1 for apple
Press 2 for soap
Press 3 for soda
Press 4 for pie
Press 5 for cake
Press 6 for bill""")
while True:
choice = int(input("enter your choice here..\n"))
if choice ==1:
print("Apple added to the cart")
total_price+=items["apple"]

elif choice== 2:
print("soap added to the cart")
total_price+= items["soap"]
elif choice ==3:
print("soda added to the cart")
total_price+=items["soda"]
elif choice ==4:
print("pie added to the cart")
total_price+=items["pie"]
elif choice ==5:
print("cake added to the cart")
total_price+=items["cake"]
elif choice == 6:
print(f"""

Total amount :{total_price}
""")
break
else:
print("Please enter the digits within the range 1-6..")
except:
print("enter only digits")

"""
Code Explanation:
A dictionary named items is created to store product names and their corresponding prices.
Example: "apple": 5 means apple costs 5 units.

one variable is initialized:

total_price to keep track of the overall bill.


A menu is printed that shows the user what number to press for each item or to generate the final bill.

A while True loop is started, meaning it will keep running until the user explicitly chooses to stop (by selecting "6" for the bill).

Inside the loop:

The user is asked to enter a number (1–6).

Depending on their input:

If they enter 1–5, the corresponding item is "added to the cart" and its price is added to the total_price.

If they enter 6, the total price is printed and the loop breaks (ends).

If they enter something outside 1–6, a warning message is shown.

The try-except block is used to catch errors if the user enters something that's not a number (like a letter or symbol).
In that case, it simply shows: "enter only digits".
"""

40 changes: 40 additions & 0 deletions loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 2 loops

# for loop:

"""
Syntax..
-> "range" : starts with 0.
-> The space after the space is called as identiation, python generally identifies the block of code with the help of indentation,
indentation is generally 4 spaces / 1 tab space..


for <variable> in range(<enter the range>):
statements you want to execute

for <varaible> in <list name>:
print(<variable>)
To print the list / or any iterator items

"""

# 1. for with range...
for i in range(3):
print("Hello... with range")
# prints Hello 3 times..

# 2.for with list

l1=[1,2,3,78,98,56,52]
for i in l1:
print("list items",i)
# prints list items one by one....

for i in "ABC":
print(i)

# while loop:
i=0
while i<=5:
print("hello.. with while")
i+=1
13 changes: 13 additions & 0 deletions saving_input_into_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ran= int(input("Enter the range of elements you want to store / insert "))
l1=[]
for i in range(ran):
l1.append(input("Enter here "))

print(l1)


"""
program first asks the user how many values they want to enter. Then, using a loop, it lets the user enter that many values one by one.
Each entered value is saved into a list called l1. Once all the values are entered, the program prints the complete list, showing
everything the user typed. It's a beginner-friendly way to learn how to collect multiple inputs and store them for later use.
"""
Loading