# coding=utf-8import randomprint("猜數字游戲開始\n")count = 0count1 = 0guessact = random.randint(5, 15)print("猜數提示:取值範圍5-15,整數值\n")while 1 == 1: guess = int( ...
# coding=utf-8
import random
print("猜數字游戲開始\n")
count = 0
count1 = 0
guessact = random.randint(5, 15)
print("猜數提示:取值範圍5-15,整數值\n")
while 1 == 1:
guess = int(input("請輸入猜想數字: "))
count+=1
count1+=1
if guess == guessact:
print('恭喜你成功猜出\n')
break
if guess > guessact:
print('\n 數字偏大,請減小')
else:
print('\n 數字偏小,請增大')
if count1 == 5:
count1 = 0
print('\n 已經猜了5次,是否繼續猜數,若結束請輸入 Y or y,否則請輸入N or n \n')
c = input()
if c == 'Y' or c == 'y':
print("\n很遺憾,退出游戲\n")
break
if c != 'N' or c != 'n':
while 1 == 1:
if c == 'N' or c == 'n':
break
print('\n警告:輸入不正確,請重新輸輸入N or n \n')
c = input()
print('\n 是否需要系統更改猜測數字,若需要請輸入 Y or y,否則請輸入N or n \n')
d = input()
if d == 'y' or d == 'Y':
guessact = random.randint(5, 15)
elif d != 'N' or d != 'n':
while 1 == 1:
if d == 'N' or d == 'n':
break
d = input('\n警告:輸入不正確,請重新輸輸入N or n; ')
print("\n 總共已猜次數:\t", count)
print('\n')