[go: up one dir, main page]

0% found this document useful (0 votes)
10 views1 page

Untitled2.ipynb - Colab

The document contains a Python script for a number guessing game where the user inputs a range and attempts to guess a randomly generated number within that range. The script checks for repeated guesses and provides feedback on whether the guess is too high or too low. The game continues until the user correctly guesses the number, at which point a congratulatory message is displayed.
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)
10 views1 page

Untitled2.ipynb - Colab

The document contains a Python script for a number guessing game where the user inputs a range and attempts to guess a randomly generated number within that range. The script checks for repeated guesses and provides feedback on whether the guess is too high or too low. The game continues until the user correctly guesses the number, at which point a congratulatory message is displayed.
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/ 1

2/21/25, 11:31 AM Untitled2.

ipynb - Colab

import random
from getpass import getpass
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: '))
print('I am thinking of a number between ' + str(num1) + ' and ' + str(num2) + ', inclusive. Guess the number!')
guess= int(getpass('enter your guess here: '))
actualnum = random.randint(num1,num2)
guesslist = []

def play(guess):

while guess != actualnum:


if guess in guesslist[0:]:
print('you already guessed that!')
guess = int(getpass('try again: '))
continue
guesslist.append(guess)
low = False
high = False
if guess > actualnum:
high = True
print('too high')

else:
low = True
print('too low')

if low or high:
guess = int(getpass('try again: '))
if guess == actualnum:
print('you got it! the number was '+str(actualnum)+'!')
play(guess)

https://colab.research.google.com/drive/1wHuRwvaFYpwYUXYJds_f94n1okb8bas9 1/1

You might also like