猜数字小游戏

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了猜数字小游戏相关的知识,希望对你有一定的参考价值。

1.最简易性
#Author:liubin
game_of_number=11
guess_number=int(input("guess number:"))
if  guess_number==game_of_number:
    print("yes,you got it")
elif guess_number>game_of_number:
    print("think smaller...")
else:
    print("think bigger...")

2.加入循环

while循环

#Author:liubin
game_of_number=11
while True:
    guess_number=int(input("guess number:"))
    if  guess_number==game_of_number:
        print("yes,you got it")
                break
    elif guess_number>game_of_number:
        print("think smaller...")
    else:
        print("think bigger...")

for循环

#Author:liubin
game_of_number=11
for  i in range(5):
    guess_number=int(input("guess number:"))
    if  guess_number==game_of_number:
        print("yes,you got it")
                break
    elif guess_number>game_of_number:
        print("think smaller...")
    else:
        print("think bigger...")

3.改进版

#Author:liubin
game_of_number=11
count=0
while count<3:
    guess_number=int(input("guess number:"))
    if  guess_number==game_of_number:
        print("yes,you got it")
        break
    elif guess_number>game_of_number:
        print("think smaller...")
    else:
        print("think bigger...")
    count+=1
else:
    print("you have tried too many times...game over")

以上是关于猜数字小游戏的主要内容,如果未能解决你的问题,请参考以下文章

java猜数字游戏代码

c语言猜数字游戏源代码

c语言设计猜数字游戏

c语言猜数字

猜数字游戏程序设计

猜数字游戏的控制台代码