Could I use a function to solve this lesson?

This is how I did it:

def iknowsomepython():
answer = 25 * 68 + 13 / 28
print(answer)
iknowsomepython()

@byte6534092225, it is good to post your code using the </> icon that appears in the menu bar at the top of the text box when you type. This preserves indentation, which is an essential part of Python syntax.

def iknowsomepython():
    answer = 25 * 68 + 13 / 28
    print(answer)
iknowsomepython()

It’s worth mentioning that you used an intermediate variable, answer, something that is often useful, but sometimes unnecessary. It is always worthwhile stopping to think whether the use of an intermediate variable makes your code more clear or more complex. Without it, you’d have

def iknowsomepython():    
    print(25 * 68 + 13 / 28)
iknowsomepython()

… since the print() function evaluates any expression within its parentheses and then prints the returned value to the screen.

To tell the truth, I don’t really have an opinion as to whether it is a good idea to use an intermediate variable in this case; I just wanted to point out that it is something worth thinking about now and then.

Thank you for the useful information I will remember that for future code.

1 Like