简体   繁体   中英

I want to prevent printing twice

Yesterday, I was helped by a grateful person to solve the problem, but it was blocked again. If I print it out like the picture below, the part error! ~ error! ~ is output twice. If I change the order of what is written after if and what else is written, it is printed twice. How can I solve this?

在此处输入图像描述 在此处输入图像描述

This is because you are running the function twice, once in the if statement, and once in the print. Store it in a variable like so:

# ...

for i in range(0, 5):

    # ...
    # ...

    bibeon = input("Enter password: ")
    chkResult = passwordChk(bibeon)
    if chkResult == 'Valid Password':
        print(chkResult)
        break
    else:
        print(chkResult)

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