1. 程式人生 > >用python實現的一個猜數字遊戲,

用python實現的一個猜數字遊戲,

使用者可以自定義猜的次數,如果在規定的次數內猜出來了,就輸出great,

 

from random import randint
s=randint(0,300)


go=int(input('請輸入猜字次數:'))


def foo(t):
i=0
while i  in range(t):
digit=int(input('please enter a number between(0,300)'))
if digit==s:
print('great!')
break
elif digit>s:
print('too large ,please try again')
else :
print('too small ,please try again')
i+=1
print('Game over!')
foo(go)

檢視連結:http://www.guoxiaowen.com/