Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using a Sentinel Value to Control a while Loop Summary In this lab, you write a while loop that uses a sentinel value to control

Using a Sentinel Value to Control a while Loop

Summary

In this lab, you write a while loop that uses a sentinel value to control a loop in a Python program. You also write the statements that make up the body of the loop.

The source code file already contains the necessary assignment and output statements. Each theater patron enters a value from 0 to 4 indicating the number of stars that the patron awards to the Guides featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie.

Instructions

Make sure the file MovieGuide.py is selected and open.

Write thewhile loop using a sentinel value to control the loop, and also write the statements that make up the body of the loop.

Execute the program by clicking the "Run Code" button at the bottom of the screen.

Input the following as star ratings: 0, 3, 4, 4, 1, 1, 2, -1

Ensure that the average output is correct.

""" MovieGuide.py

This program allows each theater patron to enter a value from 0 to 4 indicating the number of stars that the patron awards to the Guide's featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, the average star rating for the movie is displayed. """

# Initialize variables. totalStars = 0 # total of star ratings. numPatrons = 0 # keep track of number of patrons

# Get input. numStarsString = input("Enter rating for featured movie: ")

# Convert to double. numStars = float(numStarsString)

# Write while loop here

# Calculate average star rating print("Average Star Value: " + str(averageStars))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

4. Devise an interview strategy from the interviewers point of view

Answered: 1 week ago