How to remove certain statement from a function conditionally

Question:

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.

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)

Asked By: bin07

||

Answers:

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.

Answered By: bbbbbbbbb
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.