Exercise: The Cafe Reviewer

Learning Objectives: Preparing for Statistics

Before moving on to the final project, let's practice a few specific data manipulation skills:

  • String Splitting: Taking a single line of input and breaking it into usable pieces.
  • Type Conversion: Converting string pieces into integers for math operations.
  • Float Formatting: Printing averages with a specific number of decimal places.
  • Text Histograms: Using the * operator to generate a visual chart based on data.

In this exercise, you will write a program to analyze customer reviews for a local cafe. Each review consists of a Taste score (1-5) and an Atmosphere score (1-5).

Programming exercise: The Cafe Reviewer
Points: 0/1

The program should continuously ask the user for a single line of input containing two numbers separated by a space. The first number is the Taste score, and the second is the Atmosphere score.

The program will keep asking for input until the user types in an empty line.

Once the user types an empty line, the program must calculate and print the following:

  • The Average total score (Taste + Atmosphere, for a max possible total of 10) formatted to exactly one decimal place.
  • A simple histogram showing how many reviews were "Great" (a total score of 8-10) and how many were "Okay" (a total score of 2-7). You will use asterisks (*) for the histogram.

You may assume the user will always enter valid data (either an empty line, or two integers separated by a space).

Sample output
Taste and atmosphere: 4 5 Taste and atmosphere: 3 2 Taste and atmosphere: 5 5 Taste and atmosphere: 2 4 Taste and atmosphere: Statistics: Average score: 7.5 Great (8-10): ** Okay (2-7): **
Sample output
Taste and atmosphere: 5 4 Taste and atmosphere: 4 4 Taste and atmosphere: 5 5 Taste and atmosphere: Statistics: Average score: 9.0 Great (8-10): *** Okay (2-7):
When you receive a string with a space in it, you can break it apart using the string method split(). It returns a list of strings. Here is an example of splitting a full name:
name_string = "Ada Lovelace"
parts = name_string.split(" ")
first_name = parts[0]
last_name = parts[1]
print(last_name)

# This will print:
# Lovelace
Note: Because split() returns strings, you will need to use int() on those individual pieces to turn them into numbers for your math.
To print a float with exactly one decimal place, you can use an f-string with the :.1f format specifier. Here is an example of formatting a temperature reading:
temperature = 36.789
print(f"The temperature is {temperature:.1f} degrees.")

# This will print:
# The temperature is 36.8 degrees.
In Python, you can multiply a string by an integer to repeat it without needing a loop! Here is an example of generating a loading bar:
dash_count = 5
print("Loading: " + "#" * dash_count)

# This will print:
# Loading: #####