高校生でpythonを独学しています。絶対に勝てないゲームをつくってみました。
改善のよちがあったらよろしくお願いします。
python
1# Game that you cannot win. 2import time 3 4print("") 5print("-------- Rule 1: Add numbers between 1 to 10.") 6print("-------- Rule 2: The player who gets to 100 first wins.") 7print("") 8 9# CPU always start from 1 10CPU_num = 1.0 11sum = 1.0 12print(f"CPU : {CPU_num}") 13print("--------------------") 14print(f"Total Sum : {sum}") 15print("--------------------") 16 17while int(sum) <= 100: 18 # Player_num (Player's number) 19 Player_num = float(input("Player : ")) 20 # Checking either Player_num > 10 or Player_num == 0 21 if float(Player_num) > 10 or float(Player_num) == 0: 22 print("Add numbers between 1 to 10") 23 elif 0 < float(Player_num) < 1: 24 print("Cannot add floated number") 25 print("Add numbers between 1 to 10") 26 else: 27 sum += Player_num 28 time.sleep(1) 29 print("--------------------") 30 print("Total Sum : " + str(sum)) 31 print("--------------------") 32 33 # CPU_num (CPU's number) 34 CPU_num = (11 - Player_num) 35 time.sleep(1) 36 print(f"CPU : {CPU_num}") 37 sum += CPU_num 38 time.sleep(1) 39 print("--------------------") 40 print("Total Sum : " + str(sum)) 41 print("--------------------") 42 43 if int(sum) == 100: 44 time.sleep(1) 45 print("----You lose!----") 46 break 47
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/09 01:33