1. 程式人生 > >python猜數字遊戲

python猜數字遊戲

使用遞迴

#!/usr/bin/python3
#-*-encoding:utf-8-*-
#@project = demo920
#@file = test3
#@author = angel
#@creat_time = 2018/9/20 9:28

import  random
number =random.randint(1,100)
def fib():

    guess = int(input('輸入一個數字'))
    if guess==number:
        print('你猜對了')
        exit(0)
    else:

        if guess<number:
            print('你猜小了')
        else:
            print('你猜大了')
        fib()

fib()