Ask Question
10 September, 19:07

Write a simple number guessing game Python program. In this code, generate a random integer between 1-10 (both included) and ask the user to guess the number in three attempts. Print appropriate responses to the user such as "You won!" or "You failed"

+4
Answers (1)
  1. 10 September, 22:40
    0
    from random import randint

    num = randint (1,10)

    count = 0

    while count<3:

    userNum = int (input ("Guess a Number "))

    if num = =userNum:

    print ("You won")

    break

    else:

    print ("Wrong try again")

    count = count+1

    Explanation:

    Import randint from random

    generate a random number between (1,10) and assign to num

    create a loop control variable count set to 0

    In a While statement with the condition count<3 prompt user to make a guess

    if guess is correct print you won and break

    else print wrong try again and increase count by 1
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a simple number guessing game Python program. In this code, generate a random integer between 1-10 (both included) and ask the user ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers