0% found this document useful (0 votes)
6 views

Untitled4.ipynb - Colab

This document contains a Python script for a number guessing game. The player must guess a randomly generated number within a specified range, receiving feedback on their guesses. The game tracks previous guesses to prevent duplicates and continues until the correct number is guessed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Untitled4.ipynb - Colab

This document contains a Python script for a number guessing game. The player must guess a randomly generated number within a specified range, receiving feedback on their guesses. The game tracks previous guesses to prevent duplicates and continues until the correct number is guessed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

from getpass import getpass

def play_game(num1, num2, actualnum):

guesslist = []
print(f'I am thinking of a number between {num1} and {num2}, inclusive. Guess the number!')

guess = int(getpass('Enter your guess here: '))

while guess != actualnum:


if guess in guesslist:
print('You already guessed that!')
else:
guesslist.append(guess)
if guess > actualnum:
print('Too high')
else:
print('Too low')

guess = int(getpass('Try again: '))

print(f'You got it! The number was {actualnum}!')

num1 = int(input('Enter the lowest number you would like to play with: '))
num2 = int(input('Enter the highest number you would like to play with: '))
actualnum = random.randint(num1, num2)

play_game(num1, num2, actualnum)

You might also like