python猜数字(for循环限制十次)

#猜数字(for循环限制十次)
number = 45

for i in range(10):#循环十次
    print("现在开始第%s次猜数字"%(i+1))
    guess_number = int ( input ( "猜数字:" ) )
    if guess_number == number:
        print ( "恭喜你第%s次猜对了!" %(i+1))
        break#退出,破环的意思
    elif guess_number > number:
        print ( "往小点想!" )
    else:
        print ( "往大点想!" )
else:
    print("你已超过十次,欢迎下次再来!")

你可能感兴趣的:(python基础,python)