简体   繁体   中英

Could someone please help me with my Python code?

I've just started learning Python and I was hoping to get help. I'm using MU Editor and I can't get past the first "if statement." I click run, then enter "Joe" and it keeps asking me "Who are you?" Am I correct in entering this input in the run section? Or should it go in the REPL or text editor section? Thanks for the help.

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.')

so if you're using python3 make sure you have this in line 1 of your code. #!/usr/bin/env python3

Then when running the file enter this into your command line. 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.")

I cleaned up your code a bit as the while True statement wasn't necessary. Let me know if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM