代碼: 選擇全部
import random
print('1-100數字猜謎遊戲!')
num = random.randint(1,100)
guess=0
i=0
while guess != num:
i=i+1
guess = int(input('請輸入你猜的數位:'))
if guess == num:
print('恭喜,你猜對了!')
elif guess < num:
print('你猜的數小了...')
else:
print('你猜的數大了...')
print('你總共猜了%d次' % i)