Question

In: Computer Science

Write a program called whilebun.py, in which the user is asked to guess the name of...

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.

Solutions

Expert Solution

  • Program is well commented for better understanding.
  • Code snippet is provided below the typed code to understand the indentation of code.
  • Output snippet is also attached at the end.

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.


Related Solutions

You have been asked to write program that allows the user to input a first name,...
You have been asked to write program that allows the user to input a first name, middle initial (without the period), and last name of a user and then display that person’s name with the first, middle initial followed by a period, and last name last. BEFORE creating the program, use structured programming principles to document how you are going to develop the program. Use Microsoft Word to complete this part of the assessment. Answer each of the following areas:...
In Java: Write a program that generates a random number and asks the user to guess...
In Java: Write a program that generates a random number and asks the user to guess the number and keeps track of how many guesses it took If the user input is negative or zero then the loop must stop reading further inputs and display how many guesses they used If they guess the correct number display a message telling them they got it and exit the program If they guess the wrong number (but still a legal guess) you...
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
17. Write a program that generates a random number and asks the user to guess what...
17. Write a program that generates a random number and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. 18. Enhance the program that you wrote for Programming...
Write a program called listful.py, in which the user inputs names, which get added to a...
Write a program called listful.py, in which the user inputs names, which get added to a list. Your program should: · Include a comment in the first line with your name. · Include comments describing each major section of code. · Create a list. · Ask the user to input a first name or hit enter to end the list. · If the user adds a first name (i.e., anything other than a blank value): o Add the name to...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT