range(10):就相当于产生10个数字(0、1、2、3、4、5、6、7、8、9) 1. 猜数字用for循环实现: #!/usr/bin/env python # -*- coding:utf-8 -*- #Author:Mclind age = 56 for i in range(3): guess_age = int(input("guess age:")) if guess_age == age: print("yes, you got it."...
最后,将整个游戏放入一个循环中,直到用户猜对为止。代码如下:importrandomnumber = random.randint(1, 100)whileTrue:guess = int(input("请猜一个1到100之间的整数:"))ifguess == number:print("恭喜你,猜对了!")breakelifguess<number:print("猜小了,请再试一次。")else:print("猜大了,请再试一...