|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import random
- secret = random.randint(1,10)
- print("--------------我爱鱼c工作室--------------")
- temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字 : ")
- while not isinstance(temp,int):
- print("抱歉,输入不合法,",end='')
- temp = input("请输入一个整数:")
- guess = int(temp)
- if guess == secret:
- print("我草,你是小甲鱼心里的蛔虫吗?!")
- print("哼,猜中了也没有奖励!")
- else:
- while guess != secret:
- if guess >secret:
- print("哥,大了大了~~")
- else:
- print("嘿,小了小了~~")
- temp = input("哎呀,猜错了,请重新输入吧 : ")
- guess = int(temp)
- print("游戏结束")
- print("不玩啦~")
-
复制代码
这段代码一直跳不出第一个循环,是哪里出问题了呢?
input返回的是一个字符串,用isinstance来和int判断肯定为False
你需要字符串的方法
while not temp.isdigit()
|
|