Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import os, time
- clearConsole = lambda: os.system('cls' if os.name in ('nt', 'dos') else 'clear')
- def game():
- rand_number = randint(0,100)
- attempt = 0
- while True:
- clearConsole()
- try:
- guess_number = int(input('Wpisz liczbę: '))
- except:
- print('Błąd, podaj liczbę jeszcze raz')
- continue
- attempt += 1
- print(f"Próby: {attempt}")
- match guess_number:
- case guess_number if guess_number > rand_number:
- print('Liczba jest za duża')
- case guess_number if guess_number < rand_number:
- print('Liczba jest za mała')
- case rand_number:
- print('Wygrana!\nLiczba to', rand_number)
- break
- time.sleep(3)
- while True:
- match input('Zamierzasz grać? (tak/nie) ').lower():
- case ('tak'|'t'): game()
- case ('nie'|'n'): exit()
- case _: print('Niepoprawna odpowiedź\n')
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement