Python Forum

Full Version: how to make a mathematical operation without the command "print"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how to make a mathematical operation without the command "print"?

I'm studing in a university, and i need this information to learn about this program for a curse.REALY THANKS to the people that can help me.
print just shows the value of an expression or an object. Nothing with the mathematics. What do you mean?
(Mar-15-2018, 04:51 PM)wavic Wrote: [ -> ]print just shows the value of an expression or an object. Nothing with the mathematics. What do you mean?

Okey the problem is that i want to put the result of an operation, but the program not put it, only stay in white when i press run . Sorry i'm a beginner with this
Put it where? Here is some math in the interpreter:

>>> 2 * 40 / 5
16.0
Do you mean this?
You need to be more specific. Nothing prints unless you tell it to print (except the interpreter). For example:

def mult(A, b):
    result = a * b

    return result

product = mult(2, 3)
will not print anything unless you add a 'print()' function somewhere, either within the mult() function or as a line after calling the mult() function for example:

def mult(A, b):
    result = a * b

    return result

product = mult(2, 3)
print(product)
Note that you do not need to print anything, you could also use the variable 'result' in another computation or function. Remember, the print() function is for humans to see what is happening within a program, not necessarily a requirement. This ability to see is also why the print() function is a valuable tool when trouble shooting.