113k views
5 votes
1.1. (30 points) Write a program to calculate the average number of cars sold by a car agency over a period of years for the first six months of each year. First, the program will ask for the number of years. Then, the program will ask for the number of cars sold for the first six months for the first year. Similarly, the program will repeat asking for the number of cars sold for the first six months of all the remaining years. After all the iterations, the program should display the number of months, the total number of cars sold, and the average number of cars sold per month for the entire period.

1 Answer

4 votes

Answer:

count = 0

months = 0

years = int(input("Enter the number of years: "))

for year in range(1, years+1):

cars_sold = int(input("Enter the number of cars sold in first six months: "))

count += cars_sold

months += 6

print("Number of months: " + str(months))

print("Number of cars sold in total: " + str(count))

print("Average number of cars sold per month: " + str(count / months))

Step-by-step explanation:

Initialize the variables

Ask the user for the number of years

Create a for loop that iterates depending on the given number of years

Ask the user for the number of cars sold in the first six months of the year

Increment the count by given number and increment the months by 6 after each iteration

Print the months, count and, average

User Shoan
by
5.5k points