|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想问一下
零基础学python中
print("----------------我爱鱼C网-----------------")
temp = input("不妨猜猜小甲鱼心里面想的是什么:")
guess = int(temp)
while guess != 8:
temp = input("哎呀,猜错啦,再试一次吧~~~~~~~:")
guess = int(temp)
if guess == 8:
print("卧槽,你是小甲鱼心里的蛔虫吗")
print("哼,猜对了也没有奖励!")
else:
if guess > 8:
print("姐,大了!大了!")
else:
print("嘿,小啦,小啦!")
print("不玩啦,游戏结束啦~~~~~~~")可以运算出结果,但是
print("----------------我爱鱼C网-----------------")
temp = input("不妨猜猜小甲鱼心里面想的是什么:")
guess = int(temp)
while guess != 8:
guess = input("哎呀,猜错啦,再试一次吧~~~~")
if guess == 8:
print("卧槽,你是小甲鱼心里的蛔虫吗")
print("哼,猜对了也没有奖励!")
else:
if guess > 8:
print("姐,大了!大了!")
else:
print("嘿,小啦,小啦!")
print("不玩啦,游戏结束啦~~~~~~~")当重复while后的选项时,会报错误
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/Python练习文件夹/004尝试002.py", line 10, in <module>
if guess > 8:
TypeError: '>' not supported between instances of 'str' and 'int',
想请教一下这是为什么呢,是不是因为int()函数的原因呢
没有转化成整形,帮你改了一下:
- print("----------------我爱鱼C网-----------------")
- temp = input("不妨猜猜小甲鱼心里面想的是什么:")
- guess = int(temp)
- while guess != 8:
- guess = int(input("哎呀,猜错啦,再试一次吧~~~~")) # 这里没有转化成整形,所以无法比较
- if guess == 8:
- print("卧槽,你是小甲鱼心里的蛔虫吗")
- print("哼,猜对了也没有奖励!")
- else:
- if guess > 8:
- print("姐,大了!大了!")
- else:
- print("嘿,小啦,小啦!")
- print("不玩啦,游戏结束啦~~~~~~~")
复制代码
|
|