Question

Modify the python “guess the sum of 2 numbers game” so that the guest has a...

Modify the python “guess the sum of 2 numbers game” so that the guest has a limited number of guesses (4 guesses max). If the guest fails to guess in time, the program should display an appropriate message

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#Python program

import random
number1 = random.randint(1, 20)
number2 = random.randint(1, 20)
number = number1 + number2
i=1
while i<=4:
guess = int(input("Guess a Number : "))
if guess < number:
print("Your guess is too low")
elif guess > number:
print("Your guess is too high")
elif guess == number:
print("Your correctly guessed the number")
break
i=i+1

if i>4:
print("Sorry,you didn't have any attempt left. It was: ",end="")
print(number)

#screenshots

Add a comment
Know the answer?
Add Answer to:
Modify the python “guess the sum of 2 numbers game” so that the guest has a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python code for guessing game users enter the number the computer will guess 8:38 PM 100...

    python code for guessing game users enter the number the computer will guess 8:38 PM 100 nstructure.com 1. Number guessing game : (5 points) 1) Requirements: Your program will ask the user to enter a number between 1 and 1000. Then it will try to guess the correct number with the guaranteed minimal average number of guesses. Which search algorithm should you use? 2) Expected Output: Enter a number between 1 and 1000? 784 Computer guesses: 500 Type 'l' if...

  • Can someone upload a picture of the code in matlab Write a "Guess My Number Game"...

    Can someone upload a picture of the code in matlab Write a "Guess My Number Game" program. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: 1. The program starts by printing instructions on the...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Code in JAVA.................... Guess the Number In this activity, you will write a REST server to...

    Code in JAVA.................... Guess the Number In this activity, you will write a REST server to facilitate playing a number guessing game known as "Bulls and Cows". In each game, a 4-digit number is generated where every digit is different. For each round, the user guesses a number and is told the exact and partial digit matches. An exact match occurs when the user guesses the correct digit in the correct position. A partial match occurs when the user guesses...

  • Write a Java program that implements the number guessing game where the computer tries to guess...

    Write a Java program that implements the number guessing game where the computer tries to guess a number in your head. You pick a number between 0 and 100, and the computer generates a guess. You then type 1 if your number is larger than the computer’s guess, -1 if your number is smaller, and 0 if the number is correct. The computer should keep trying to guess the number by adjusting the guess based on your feedback (so if...

  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

  • Hangman is a game for two or more players. One player thinks of a word, phrase...

    Hangman is a game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers, within a certain number of guesses. You have to implement this game for Single Player, Where Computer (Your Program) will display a word with all characters hidden, which the player needed to be guessed. You have to maintain a dictionary of Words. One word will be selected by your program....

  • Write a guessing game where the user has to guess a secret number. After every guess...

    Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively. Using PYTHON.

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT