Question

In: Computer Science

Python It's time to put everything together!  This week you will write a program that mimics an...

Python

It's time to put everything together!  This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. I leave the bulk of design up to you (hint - think A LOT about it before you start programming!!) but it should include all of the following:

The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price.

- Ensure the user types in numbers for quantities
- "Hardcode" the price of items into a list and pick from it randomly for each item
- Get the user's name and shipping address
- Separate functions that compute tax (bonus - different based on shipping state?) and shipping costs (based on number of items?), and returns their values to the main program
- Bonus: Set up a list of lists with all the items/prices in your store and only let users pick from that list

Solutions

Expert Solution

Program Code Screenshot:

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

import random
def getTax(s):
state=input("Enter state")#read state name to compute tax amount
if state=="state1":
tax=0.1*s
elif state=="state2":
tax=(0.2*s)
else:
tax=0.3*s
return tax#return tax amount

def getShippingCharges(n):
return 10*n#returns shipping charges(10 for each item)

prices=[100,200,300,400]
items=["item1","item2","item3","item4"]#names of items are stored in list
l=[]
for i in range(len(items)):
r=random.randint(0,len(prices)-1)
l.append([items[i],prices[r]])#prices are stored with item names in l list
prices.pop(r)

total=0
num_items=0
cart=[]
while True:
print("Item Price")
print("----------------")

for i in l:
print(i[0],i[1],sep="\t")#print the items available
print("Enter name of item to add to cart:")
n=input()
if n=="done":
break
q=int(input("Enter Quantity"))#read name and item quantity
num_items+=q
for k in l:
if k[0]==n:
total=total+(q*k[1])#compute total
cart.append([n,q])#add item to cart

username=input("Enter Name:")
address=input("Enter shipping address")#read inputs from user
tax=getTax(total)#get tax and charges for shipment
ship_charges=getShippingCharges(num_items)
print()
print("Purchase summary")
print("-----------------")#print the details
print("Items Quantity")
for i in cart:
print(i[0],str(i[1]),sep="\t")
print("The cart amount is:",total)#print the cart amount
total=total+tax+ship_charges#calculate total amount that includes the tax and ship charges
print("The shipment charges are:",ship_charges)
print("The tax is:",tax)#print the details
print("The total cost is:",total)


Related Solutions

Python This week you will write a program in Python that mimics an online shopping cart...
Python This week you will write a program in Python that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
Python This week you will write a program in Pyhton that mimics an online shopping cart...
Python This week you will write a program in Pyhton that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
This week you will write a program that mimics an online shopping cart . You will...
This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers for quantities -...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
FOR PYTHON: Write a python program for a car salesperson who works a five day week....
FOR PYTHON: Write a python program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown...
Write a Python program that reads in two times, an earlier time and a later time,...
Write a Python program that reads in two times, an earlier time and a later time, and prints the difference between the two times in minutes as well as in hours/minutes. The format of the time is HH:MMAM or H:MMAM or HH:MMPM or H:MMPM. Also the AM or PM may be in lower case. A sample run of the program is shown below: $ python3 Time.py Enter Earlier Time: 9:36aM Enter Later Time: 6:22PM Number of minutes between 9:36aM and...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you...
Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you are interested in - a hobby, a job, history, cooking, travel, sports, a foreign language, music, art, whatever you have some passion about. Find an API that connects with your interest. Write a Python program that demonstrates the use of that api AND does some web scraping as well. It must include the ability to download images to your computer. Submit the following to...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT