Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove certain statement from a function conditionally

So let’s say I have a function of

def question():
    print("")
    question_section = str("B" + str(quiz_nmbr + 1))
    print("Question", str(quiz_nmbr) + ": " + str(sheet[question_section].value))
    question_become = str(input("Type your question: "))
    sheet[question_section].value = question_become 
    book.save('Quiz_Problems.xlsx')

Then let’s say one time I wanted to call the question() function again.

However, I don’t want print("Question", str(quiz_nmbr) + ": " + str(sheet[question_section].value)) to be printed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there anyway to just remove that statement for certain condition? and by condition what I mean is let’s say I wanted to call the function in if else statement (which condition matters to give different output)

>Solution :

Try this:

def question(prompt):
    print("")
    question_section = str("B" + str(quiz_nmbr + 1))
    if prompt:
        print("Question", str(quiz_nmbr) + ": " + str(sheet[question_section].value))
    question_become = str(input("Type your question: "))
    sheet[question_section].value = question_become 
    book.save('Quiz_Problems.xlsx')

Then, inside your if/else clause, you can call question(True) or question(False) as desired.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading