Guess the Number

Write a program that allows a user to guess a dice roll. The user should be asked to pick a number from 1 to 6. A dice should then be rolled, and if the user guessed correctly, the program will display “You Won!”.

Guess a number between 1 and 6: 5
Random Number: 5
YOU WON!
SET secret TO RANDOM(1,6)

OUTPUT "Guess a number between 1 and 6"
INPUT guess

IF guess = secret THEN
    OUTPUT "Correct! You guessed it"
ELSE
    OUTPUT "Wrong! The number was ", secret
ENDIF
import random

secret = random.randint(1, 6)

guess = int(input("Guess a number between 1 and 6: "))

if guess == secret:
    print("YOU WON!")
import random

# Pick a random number between 1 and 6
secret = random.randint(1, 6)

# Ask the user for their guess
guess = int(input("Guess a number between 1 and 6: "))

# Check with if statement
if guess == secret:
    print("YOU WON!")

Extension

Extend the program to allow the user to have three guesses. Each guess should check to see if it matched the random number.

Guess a number between 1 and 6.
Guess 1: 5
Guess 2: 6
Guess 3: 1
You guessed correctly with 5!

Target

You should be able to use If Statements to solve a problem.