diff --git a/billing.py b/billing.py index c3fff306097..f6fb387101c 100644 --- a/billing.py +++ b/billing.py @@ -1,3 +1,70 @@ -prices = [12.99, 5.49, 8.75] -total = sum(prices) -print(total) \ No newline at end of file +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". +""" + diff --git a/loops.py b/loops.py new file mode 100644 index 00000000000..50d4ac6ef7b --- /dev/null +++ b/loops.py @@ -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 in range(): + statements you want to execute + +for in : + print() +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 \ No newline at end of file diff --git a/saving_input_into_list.py b/saving_input_into_list.py new file mode 100644 index 00000000000..03caac68016 --- /dev/null +++ b/saving_input_into_list.py @@ -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. +""" \ No newline at end of file