Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why do my variables display first instead of my print statements

+1 vote
asked Dec 16, 2022 by Liam N (130 points)
How come my variables are displaying before my prints statement?

Here's the link: https://onlinegdb.com/lfAWJW3Xl

1 Answer

0 votes
answered Dec 16, 2022 by Peter Minarik (86,900 points)
edited Dec 23, 2022 by Peter Minarik

You have to understand that function calls execute immediately, not when you reference the variable storing the result of the function call.

Try this one:

score = 0
name = input("Come on down, what is your name?")
intro = (f"\nWelcome {name} to 'Dad Joke Mania' the show where you finsh the dad joke with the correct punch line!\n")
#questionpick = input("Pick a number 1 - 5...")
question1 = "Q: How to you make a space party? A:..."
question2 = "Q: What do call a well-balenced horse A:..."

print(intro)
print("Now answer this question.")
answer1 = input(question1)
if answer1 == "you planet":
    print("correct")
else: 
    print("Inocorrect :(")

print("Now answer this question.")
answer2 = input(question2)
if answer2 == "stable":
    print ("correct!")
else: 
    print("Inocorrect :(")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...