找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2299|回复: 2

[已解决] while语句循环问题

7

主题

15

帖子

15

积分

贫民

积分
15
LisaWang 发表于 2018-3-15 09:47:46 | 显示全部楼层 |阅读模式
各位大大好,我刚开始学python,在编写while语句时遇到了问题,程序只认我第一次输入的字符,后面无论是否输入正确都显示错误。真心不知道哪里出错了。以下是代码:

#!/usr/bin/python
# Filename: if.py

name = "Riddler"
guess = input('Enter a name which Lisa likes: ')

while guess != name:
        if guess == "Lisa":
                print ('You were a fish')
                guess == input('once more: ')
        else:
                print ('No,you were wrong.')
                guess == input('another chance: ')
else:
        print ('Congratulations, you guessed it.')


回复

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2018-3-15 10:23:17 | 显示全部楼层
guess == input('once more: ')
guess == input('another chance: ')
这里是用 = 赋值吧,不应该是==判断?
回复 支持 1 反对 0

使用道具 举报

7

主题

15

帖子

15

积分

贫民

积分
15
LisaWang  楼主| 发表于 2018-3-15 10:31:38 | 显示全部楼层
sheeboard 发表于 2018-3-15 10:23
guess == input('once more: ')
guess == input('another chance: ')
这里是用 = 赋值吧,不应该是==判断? ...

啊啊啊啊是的是的确实是这里错了!!感谢感谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表