Movie Ratings
Write a program that allows a user to record the ratings for a group of people after visiting the cinema. The program should ask the user for the name of a movie and how many people went to see it. It should then collect a star rating (between 1 and 5) from each person, storing the ratings in a 1-D array. Finally, the program should display the movie name, all the ratings, and the average overall rating.
Enter the movie name: The Study Party How many people watched the movie? 4 Enter rating for person 1 (1-5): 5 Enter rating for person 2 (1-5): 5 Enter rating for person 3 (1-5): 4 Enter rating for person 4 (1-5): 5 The Study Party was rated: Person 1 : 5 stars Person 2 : 5 stars Person 3 : 4 stars Person 4 : 5 stars Average rating: 4.75
DECLARE movie_name AS STRING
DECLARE num_people AS INTEGER
DECLARE ratings[num_people] AS INTEGER
DECLARE total AS INTEGER
DECLARE average AS REAL
OUTPUT "Enter the movie name:"
INPUT movie_name
OUTPUT "How many people watched the movie?"
INPUT num_people
SET total TO 0
DECLARE ratings[num_people] AS INTEGER
FOR i FROM 0 TO num_people - 1 DO
OUTPUT "Enter rating for person", i + 1
INPUT ratings[i]
SET total TO total + ratings[i]
END FOR
SET average TO total / num_people
OUTPUT movie_name, "was rated:"
FOR i FROM 0 TO num_people - 1 DO
OUTPUT "Person", i + 1, ":", ratings[i], "stars"
END FOR
OUTPUT "Average rating:", average
movie_name = input("Enter the movie name: ")
num_people = int(input("How many people watched the movie? "))
ratings = [int] * num_people
total = 0
for i in range(num_people):
ratings[i] = int(input("Enter rating for person " + str(i + 1) + " (1-5): "))
total = total + ratings[i]
average = total / num_people
print()
print(movie_name, "was rated:")
for i in range(num_people):
print("Person", i + 1, ":", ratings[i], "stars")
print("Average rating:", average)
# Ask for the movie name
movie_name = input("Enter the movie name: ")
# Ask how many people watched it
num_people = int(input("How many people watched the movie? "))
# Create an array to store ratings
ratings = [int] * num_people
total = 0
# Get rating from each person
for i in range(num_people):
ratings[i] = int(input("Enter rating for person " + str(i + 1) + " (1-5): "))
total = total + ratings[i]
# Calculate average rating
average = total / num_people
# Display all ratings
print()
print(movie_name, "was rated:")
for i in range(num_people):
print("Person", i + 1, ":", ratings[i], "stars")
# Display average rating
print("Average rating:", average)
Extension
Extend the program to include input validation so that ratings can only be between 1 and 5.
Enter the movie name: The Study Party How many people watched the movie? 4 Enter rating for person 1 (1-5): 5 Enter rating for person 2 (1-5): 5 Enter rating for person 3 (1-5): 44 Ratings must be between 1 and 5. Enter rating for person 3 (1-5): 4 Enter rating for person 4 (1-5): 5 The Study Party was rated: Person 1 : 5 stars Person 2 : 5 stars Person 3 : 4 stars Person 4 : 5 stars Average rating: 4.75