SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Lists And Tuples
Exercise:
Programming Exercises
Question:1 | ISBN:9780132576376 | Edition: 2

Question

Total Sales
Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in a list. Use a loop to calculate the total sales for the week and display the result.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Total Sales Python code:

#Prompt and asks the user to enter a store’s sales for each day of the week. 
#The amounts should be stored in a list. Use a loop to calculate the total
#sales for the week and display the result.
daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
totalSales = []

# Ask user for sales input for each day of the week
for day in daysOfWeek:
    sale = float(input(f"Enter sales for {day}: "))
    totalSales.append(sale)

# Calculate the total sales for the week
total = sum(totalSales)

# Display the total sales
print(f"\nTotal sales for the week: ${total:.2f}")

Executed Output:

Enter sales for Monday: 250
Enter sales for Tuesday: 100
Enter sales for Wednesday: 200
Enter sales for Thursday: 300
Enter sales for Friday: 400
Enter sales for Saturday: 100
Enter sales for Sunday: 10

Total sales for the week: $1360.00

 

0 0

Discussions

Post the discussion to improve the above solution.