I need to write a code in Python using the while loop to do the following:
- Require the user to enter the names of all pupils in a class.
- The user should be able to type “Stop” to indicate that the names of all the students have been entered.
- Print out the total number of names the users entered after the loop has been exited.
Here is the is the code I thus far:
print ("""Enter the names of all the pupils in your class.
Type 'Stop' to indicate that all the names have been entered.""")
count_names = {}
while True:
pupil_names = input("Enter a name: ")
# I know there is code missing here, but I can not figure out what it must be
# I have 'count_names' as my counter variable
if pupil_names == "Stop":
print(f"There are {count_names} students")
break
I have searched everywhere for help but can't find anything.
Answers / Help that have come the closest:
count number of names in list in python
Counting the input in a while loop?