194k views
4 votes
Write a program that asks users to enter letter grades at the keyboard until they hit enter by itself. The program should print the number of times the user typed A on a line by itself.

1 Answer

6 votes

Answer:

The complete code in Python language along with comments for explanation and output results are provided below.

Code with Explanation:

# the index variable will store the number of times "A" is entered

index = 0

while True:

# get the input from the user

letter = input('Please enter letter grades: ')

# if the user enters "enter" then break the loop

if letter == "":

break

# if user enters "A" then add it to the index

if letter == "A":

index = index + 1

# print the index variable when the loop is terminated

# the str command converts the numeric type into a string

print("Number of times A is entered: " + str(index))

Output:

Please enter letter grades: R

Please enter letter grades: A

Please enter letter grades: B

Please enter letter grades: L

Please enter letter grades: A

Please enter letter grades: A

Please enter letter grades: E

Please enter letter grades:

Number of times A is entered: 3

Write a program that asks users to enter letter grades at the keyboard until they-example-1
User Hatellla
by
3.7k points