Shopping Cart using python.

0


Shopping Cart using Python


This code creates a simple shopping cart program where the user can add items and their prices,
and then it calculates and displays the total cost of all the items.
The program continues to take inputs until the user quits by entering "q".


Description :
This code is a program for a simple shopping cart system, written in Python.
The code allows users to input items and their respective prices, 
and it calculates the total cost of all the items in the shopping cart.
The code is easy to understand, making it an ideal choice for beginners looking to learn the basics of programming and creating simple programs.
The code utilizes lists and variables to store the information entered by the user.
The items and their prices are stored in separate lists, and a variable is used to keep track of the total cost of all items in the cart.
The program uses a loop to continuously take inputs from the user until they choose to quit by entering "q".
Finally, the code displays the list of items and the total cost of the items in the cart.
This makes it easy for users to review their purchases and ensure that the total cost is accurate.
In conclusion, the code is a well-written, simple, and effective implementation of a shopping cart system. It provides a good foundation for those looking to learn about programming and basic algorithms.





This code implements a simple shopping cart program.
1)It initializes three variables:
  items list to store the names of items added to the cart.
  prices list to store the prices of the items.
  total variable to store the sum of the prices of all items.
2)It runs an infinite loop to allow the user to enter items until they enter "q".
  The user is prompted to enter the name of an item.
  If the entered name is "q", the loop breaks.
  If the name is not "q", the user is prompted to enter the price of the item and the name and price are added to the items and prices lists, respectively.
3)Finally, it prints the list of items and the total cost of all items.
  The names of items are printed first.
  The total cost is calculated by summing up all the prices in the prices list.
  The total cost is then printed as the result.

Code :

#shopping cart
items=[]
prices=[]
total=0
while True:
  item=input("Enter the Name of item(Press q to quit):")
  if item.lower()=="q":
    break
  else:
    price=float(input(f"Enter the Price of {item}: $"))
    item=items.append(item)
    price=prices.append(price)
print()
print("-----Your Items-----")
for item in items:
   print(item)
for price in prices:
    total+=price
print("--------****--------")
print(f"Your total amount is :{total} $")
 


Here is a simple python program of Shopping Cart.

Just copy the code and paste it in your preferred Code Editor.

if you have any Doubt Feel Free to comment down,Our team will Respond as soon as Possible.

Thanks for Reading,

Regards,

Team Dekoders.

Tags

Post a Comment

0Comments
Post a Comment (0)