0

How do you return a value that is inputted

def multiply(x, y): return x * y a = input() b = input() operation = multiply print(operation(a, b)) this code gives me an error

28th Jan 2017, 6:21 PM
Glenn Bennett
Glenn Bennett - avatar
5 ответов
+ 4
If you want to do it step by step, you can assign: a = input() b = input() a = int(a) b = int(b) but it's more convenient to write: a = int(input ()) b = int(input ()) or (the cleanest option) leave the variables as they are and force the type only in the method definition, like VEdward did.
28th Jan 2017, 9:28 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
because the input is string... you need to convert them to integer then multiply... you can't multiply strings use this.. return int(a)*int(b)
28th Jan 2017, 6:46 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
+ 1
how do you do that? int = a int = b ??
28th Jan 2017, 6:42 PM
Glenn Bennett
Glenn Bennett - avatar
+ 1
a=int (input ()) b=int (input ())
28th Jan 2017, 7:04 PM
voryamiraki
voryamiraki - avatar
+ 1
thank you for you guys' help. i really appreciate this.
28th Jan 2017, 9:29 PM
Glenn Bennett
Glenn Bennett - avatar