Uploaded by Zachary Rogers

PE 08

advertisement
04/01/2020
Programming Exercises pg. 413, #1 and #3
1)
#03/02/2020
#PE 8, 1
#This program takes a store's sale numbers for each day
#of the week, and displays the total sales for the week
#Main function that set list elements
def main():
total = 0.0
dailySales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
index = 0
daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"]
#For loop to pass sales amount
for index in range(7):
print("Enter the amount of sales for", daysOfTheWeek[index])
dailySales[index] = float(input("Enter the sales here: "))
#Calculates total
total = total + dailySales[index]
#Displays total weekly sales
print("The total sales for the week is $", format(total, '.2f'))
main()
3)
#03/02/2020
#PE 8, 3
#This program collects total rainfall for 12 months
#Then displays total for the year, monthly average
#With highest and lowest amounts
#Set list elements
months = ["January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"]
values = []
year = []
#For loop to pass total rain amounts to elements
for i in months :
values.append(float(input("Enter total rain for the month of " + i + ": ")))
print()
#Function to get total amount of rainfall
def total():
print("The total rainfall for the year was", sum(values), "inches")
total()
#Function to get average monthly rainfall
def average():
print("The average monthly rainfall was ", float(sum(values)/ 12), "inches")
average()
#Function to get highest rainfall amount
def highest():
print("The highest monthly rainfall was during the month of",
months[values.index(max(values))] )
print("It had", max(values), "inches of rain")
highest()
#Function to get lowest rainfall amount
def lowest():
print("The lowest monthly rainfall was during the month of",
months[values.index(min(values))] )
print("It had ", min(values), "inches of rain")
lowest()
Download