我想防止两次打印 [英] I want to prevent printing twice

查看:213
本文介绍了我想防止两次打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,一个感激的人帮助我解决了这个问题,但是又被封锁了.如果像下面的图片一样打印出来,部分error! ~将被输出两次.如果更改if之后写入的内容和else写入的内容的顺序,则会打印两次.我该如何解决?

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! ~ 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?

推荐答案

这是因为您两次运行该函数,一次在if语句中,一次在打印中.将其存储在这样的变量中:

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)

这篇关于我想防止两次打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆