+ 1

Is this code correct?

x = input() y = input() print(x*y)

10th Jul 2022, 2:34 AM
CHONG ZI XU Moe
CHONG ZI XU Moe - avatar
5 Answers
+ 8
no, you'd need to change the input to integers. x = int(input()) ...
10th Jul 2022, 2:36 AM
Slick
Slick - avatar
+ 3
.... addition to all others: at least one of x and y should be converted. And .... integer is just one opportunity
10th Jul 2022, 6:32 AM
Oma Falk
Oma Falk - avatar
+ 1
Thanks
10th Jul 2022, 12:27 PM
CHONG ZI XU Moe
CHONG ZI XU Moe - avatar
0
It's not correct because input() returns string and it doesn't make sense to multiply to strings. By the way it will work if: 1- both x and y are converted to float OR integer like this: x = int(input()) y = float(input()) print(x * y) Inputs: 2, 3 Output: 6.0 2- x OR y is converted to float OR integer and the other remains string. This way the string will be repeated by the integer OR float. x = str(input()) y = int(input()) print(x * y) Inputs: 2, 3 Output: 222
12th Jul 2022, 4:55 PM
MOJTABA MEHRI
MOJTABA MEHRI - avatar