# Looks great! # . I would come up with a better name for d
# test if the user wants to quit...
# Is not quite right... Change this print('I thought of another number, try again')
# to something more like "Not Quite, Please try again"
from random import randint
play = input('You want to start? y/n ')
def play_game():
# Put the rules here
# While loop goes here
d = randint(7, 50)
computer_num = randint(1, d)
lives = d // 2
while lives > 0:
try:
num = int(input(f'enter number from 1 to {d}, you have {lives} attempts left '))
if num > d or num < 1:
raise ValueError
except:
print('incorrect input, try again')
continue
if num == computer_num:
print(f'you won, I thought number {computer_num}')
return None
else:
lives -= 1
if lives > 0:
print('I thought of another number, try again')
print(f'you lost, I thought number {computer_num}')
play = input('You want to start the game[y/n]: ')
while play.lower() == 'y':
play_game()
play = input('You want to play again? y/n ')
from random import randint
play = input('You want to start? y/n ')
def play_game():
# Put the rules here
# While loop goes here
game_size = randint(7, 50)
computer_num = randint(1, game_size)
lives = game_size // 2
while lives > 0:
try:
num = int(input(f'Enter number from 1 to {game_size}, you have {lives} attempts left: '))
if num > game_size or num < 1:
raise ValueError
except:
print('Incorrect input, try again.')
continue
if num == computer_num:
print(f'You won, I guessed this number! {computer_num}')
return None
else:
lives -= 1
if lives > 0:
print('Good try, you still have a chance!')
print(f'You lost, I guessed this number! {computer_num}')
play = input('You want to start the game[y/n]: ')
while play.lower() == 'y':
play_game()
play = input('You want to play again? y/n ')
Comments
Leave a comment