简单的猜数字小游戏--Python
猜数字小游戏:
#coding=utf-8
import random
answer =random.randint(1,100) #生成随机数
n=int (input("Please input num(1-100):")) #玩家输入数值 ;int强制转换,不转化的会出现类型报错,因为字符类型是不能参与比较运算。
while n!=answer: #判断输入数字大小
if n>answer:
n=int (input("num is more please continue input:"))
elif n<answer:
n = int (input ("num is less please continue input:"))
print ("YOU WIN !") #输入答案正确,游戏结束