输入为空时出现错误,我尝试了很多选项,但被卡住了

时间:2019-12-19 01:50:00

标签: python python-3.x

这是我的代码

import random
import os
import time

def Num_guess():
    rand_num = (random.randint(0,9))

    print("Welcome to guess the number. ")
    guess_num = int(input("What number am i thinking of. "))

    if guess_num == rand_num:
        print("correct! ")
        time.sleep(1.5)
        os.system("cls")
        Num_guess()
    elif guess_num > 10:
        print("invalid. 0-9 only")
        time.sleep(1.5)
        os.system("cls")
        Num_guess()
    elif guess_num < 0:
        print("invalid. 0-9 only")
        time.sleep(1.5)
        os.system("cls")
        Num_guess()
    elif guess_num != rand_num:
        print("Nope not corrrect. The number was ")
        print(rand_num)
        time.sleep(1.5)
        os.system("cls")
        Num_guess()

Num_guess()

0 个答案:

没有答案