def eval(): l = input('Enter L:') v = input('Enter V:') t = input('Enter t:') if l==None: v=int(v) t=int(t) res = v*t print(res) elif v==None: res = +l/+t print(res) elif t==None: res = +l/+v print(res) 

How to display the result of res ? return and print do not return a value to the console.


How can I output the same result res without using the console and input ? If the parameters l , v , t defined immediately in the code:

 def eval(l,v,t): 

But how to calculate l, v, t without specifying the value (None) when calling this function eval(4, ,7) ?

    1 answer 1

    If I understood correctly, only 2 arguments are always transmitted. First, input always returns a string (if you didn’t enter anything, it will return an empty string, not None ). Secondly, you translate strings in numbers only in if , but not in elif . As a result, the function should look something like this:

     def eval(): l = input('Enter L:') v = input('Enter V:') t = input('Enter t:') if l == '': print(int(v)*int(t)) elif v == '': print(int(l)/int(t)) elif t == '': print(int(l)/int(v)) 

    If you want to call a function from code, you can declare it like this.

     def eval(l = '', v = '', t = ''): 

    (if any of the arguments is not passed, it will by default be set to '' ), but then when calling you will have to specify which arguments you are passing, for example:

     eval(l=9, t=3) 

    It would be nice to add some output if the argument set is incorrect (add an else , or throw an exception). And it is also possible to abandon the use of the name eval , since the python already has a built-in function with that name.

    • Yes, you understood correctly. Thank! - Sergey Alekseev