Python Forum
Python: why skip the 'else' if password is wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python: why skip the 'else' if password is wrong
#1
name_expected='Max'
while True:
print( 'Who are you')
name = input()
if (name != name_expected):
continue
print (name_expected +' please enter your password' )
pd= input()
if (pd == '123'):
break
else:
print('password is not right, start from beginning of the loop') ----------> why can not reach here if give a wrong password.
print(' you are granted')


Please help with the above code. If enter a correct name but wrong password, I want to tell wrong password. Thanks!

name_expected='Max'
while True:
    print( 'who are you')
    name = input()
    if (name != name_expected):
        continue
    print (name_expected +' please enter your password' )
    pd= input()
    if (pd == '123'):
        break
    else:
        print('password is not right, start from beginning') # why can not reach here if wrong password
print(' you are granted')              
    
 
Please help with the above code. If I enter a correct name but wrong password, I want to print the else statement above mentioning a wrong password. Thanks!
Reply
#2
Works fine for me. breaks are unreliable as it's somewhat difficult to tell which level you are breaking from. return from a function instead.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  help me to make my password list in python >>> Oktay34riza 0 576 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,536 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  need to skip password prompt, continue... tester_V 2 1,463 Oct-19-2021, 05:49 PM
Last Post: tester_V
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,649 May-26-2021, 06:21 AM
Last Post: Melcu54
  How to skip to a different line while importing a different script kat_gamer 2 2,235 Feb-03-2021, 04:10 AM
Last Post: deanhystad
  How to skip a folder directory in a loop mfkzolo 2 12,535 Nov-18-2020, 07:56 AM
Last Post: mfkzolo
  How to skip LinkedIn signup link using python script? Mangesh121 0 1,792 Aug-26-2020, 01:22 PM
Last Post: Mangesh121
  How to calculate column mean and row skip non numeric and na Mekala 5 4,931 May-06-2020, 10:52 AM
Last Post: anbu23
  Functions, skip an arugment SpongeB0B 2 2,098 Mar-27-2020, 12:10 PM
Last Post: SpongeB0B
  python gives wrong string length and wrong character thienson30 2 2,992 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020