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.

How do I put equations, such as somebodies age, plus a variable that holds a number, into a print function?

–3 votes
asked Dec 8, 2020 by Charles Weaver (230 points)
I'm struggling to add age and variables together. Does anybody know how to do it?

1 Answer

0 votes
answered Dec 8, 2020 by xDELLx (7,630 points)
selected Dec 8, 2020 by Charles Weaver
 
Best answer

This is a very vague question or maybe not worded correctly.

Nevertheless ,Below is what I understood.

age = 5
variable_holding_number = 1
print("Equation adding age to an variable_holding_number ==> " +
            str(age) +" + "+ str(variable_holding_number)
            + " = "+ str(age+variable_holding_number))


print() function expects  parameters as strings ,so you will need to convert int variables to strings using the str() function.

commented Dec 8, 2020 by Charles Weaver (230 points)
Sorry. Figured it out about 15 minutes ago.
commented Dec 9, 2020 by xDELLx (7,630 points)
Cheers!! :)


.
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.
...