Total Sales Design a program that asks the user to enter a store’s sales for eac
ID: 3854940 • Letter: T
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 an array. Use a loop to calculate the total sales for the week and display the result.
Need: variable lists, IPO Chart, pseudocode, Flowchart, and working Python code.
Lottery Number Generator
Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element. (Use the random function that was discussed in Chapter 6.) Then write another loop that displays the contents of the array.
Need: variable lists, IPO Chart, pseudocode, Flowchart, and working Python code.
Explanation / Answer
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 an array. Use a loop to calculate the total sales for the week and display the result.
variable list : Sunday Monday Tuesday Wednsday Thursday Friday Saturday total store_sale
array : store_week_sales
IPO Chart
Input Data Processing Steps Output Data
Every day sales entry get sales of evry day every day sales
none store all day sales in array
none calculate total of total sales of week
every day sales
Python code.
Sunday = int(input("Enter the store sales for Sunday: "))
Monday = int(input("Enter the store sales for Monday: "))
Tuesday = int(input("Enter the store sales for Tuesday: "))
Wednsday = int(input("Enter the store sales for Wednsday: "))
Thursday = int(input("Enter the store sales for Thursday: "))
Friday = int(input("Enter the store sales for Friday: "))
Saturday = int(input("Enter the store sales for Saturday: "))
store_week_sales = [Sunday, Monday, Tuesday, Wednsday, Thursday, Friday, Saturday] #store value of each day
total = 0
for store_sale in store_week_sales:
total += store_sale #calculate total
print ("Total week sales: %.2f" % total)
Lottery Number Generator
Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element
variable list : i
array :randno
IPO Chart
Input Data Processing Steps Output Data
empty list array empty array list generated empty array
loop generate 7 digit no
random no between 0 to 9
append no in array
print random no 7 digit random no
Python code.
# Import random and define list
import random
randno=[]
# Generate random lottery number list
for i in range (7): #seven random numbers, each in the range of 0 through 9, and assign each number to a list element.
randno.append(random.randrange(0,9))
# Print results
print ('Your randomly generated lottery number is: {}.'.format(randno))