[英]Could someone please help me with my Python code?
我刚刚开始学习 Python,希望能得到帮助。 我正在使用 MU 编辑器,但我无法通过第一个“if 语句”。 我点击运行,然后输入“Joe”,它一直在问我“你是谁?” 我在运行部分输入此输入是否正确? 还是应该在 REPL 或文本编辑器部分中使用 go? 谢谢您的帮助。
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello, Joe. What is the password? (It is a fish.)')
password = input()
if password == 'swordfish':
break
print('Access granted.')
因此,如果您使用的是 python3,请确保在代码的第 1 行中有此内容。 #!/usr/bin/env python3
然后在运行文件时将其输入到命令行中。 python3 "filename.py"
#!/usr/bin/env python3
name = input('Who are you?: ')
if name == "Joe":
print(f"Hello, {name}.")
password = input('What is the password? (It is a fish.)')
if password == 'swordfish':
print('Access granted.')
else:
print('Access denied.')
else:
print(f"Sorry {name}, I don't know you.")
我清理了您的代码,因为不需要while True
语句。 如果您有任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.