Python入門 数当てゲーム
import random import time low = 1 high = 200 answer = random.randint(low, high) count = 0 start_time = time.time() print(f'{low}から{high}の数を当ててください。') while True: print('') print('入力してください > ', end='') guess = int(input()) count += 1 if answer > guess: print('答えはもっと大きいです。') elif answer < guess: print('答えはもっと小さいです。') else: print('正解です。') break end_time = time.time() print(f'{count}回で正解しました。') print(f'{int(end_time - start_time)}秒で正解しました。')