刚开始学习python,python版本为python33,学习的第一个例子为猜数字游戏,代码如下:
import random
secret=random.randint(1,99)
print(secret)
guess=0
tries=0
print ("start!!!!!")
while guess != secret and tries < 6:
guess=int(input("What's yer guess? "))
if guess < secret:
print ("too low")
tries=tries+1
elif guess > secret:
print ("too high")
tries=tries+1
if guess == secret:
print ("right!!!!!")
print ("the right num is",secret)
else:
print ("game over!!!")
需要注意的地方:
1.涉及条件判断的行,也就是最后有冒号的行,下一行一定要缩进,否则会报错