In: Computer Science
Write a program called whilebun.py, in which the user is asked to guess the name of your favorite DBVac vacuum cleaner model. Your program should:
· Include a comment in the first line with your name.
· Include comments describing each major section of code.
· Set a variable called vacname to be equal to the name of your favorite DBVac vacuum cleaner model.
· Ask the user to guess the name. Allow the user to make up to three guesses, evaluating each guess for correctness immediately after the guess is made.
o The user’s guess shouldn’t be required to be case sensitive to be correct. For instance, if your favorite model is the Hare Razer, but the user inputs “HARE RAZER”, then that should be counted correct (as should “hare razer”, “hArE rAzEr” and any other combination of capital and lower-case letters).
o If the user guesses wrong, let them know, tell them how many guesses they have left, and have them guess again (up to three guesses total).
· If the user guesses the correct name:
o Stop asking the user to guess (even if they have not yet guessed three times).
o Congratulate the user on their guessing skills.
o Tell the user how many guesses it took them to guess correctly.
· If the user runs out of guesses without guessing the correct name:
o Console the user by telling them that, while they have failed in this task, it’s going to be okay.
Program:
# Write your name here # Set a variable called vacname to be equal to the name of your favorite DBVac vacuum cleaner model vacname = 'Hare Razer' # initial guess count = 0 guess_count = 0 # loop while guess count < 3 while guess_count < 3: # increment guess count by 1 each time guess_count += 1 # ask for user guess user_guess = input("Guess the name: ") # if user guess it correct # Stop asking the user to guess (even if they have not yet guessed three times). if vacname.lower() == user_guess.lower(): # Congratulate the user on their guessing skills print('Congratulations! You have guessed it correct.') # Tell the user how many guesses it took them to guess correctly print('You took', guess_count, 'guesses to guess it correct.') # break the loop break else: # If the user guesses wrong # let them know, tell them how many guesses they have left print("Sorry! You have guessed it wrong.") print("You have", 3-guess_count, "guesses left.")
Code Snippet:
Output Snippets:
I hope you got the provided solution.
Thank You.