Can someone help me take multiple numbers from an input (a string) and help me map it to INT? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone help me take multiple numbers from an input (a string) and help me map it to INT?

So i can take an input that is just one number, or a prefabricated list and change them into integers and work with them, however i'm trying to take an input of "x, y" and convert those to integers so that i can perform operations. variable = int(input(x, y)) It feels like i should be able to easily figure this out, but i cant. Please help! Thanks :D

17th Oct 2020, 12:11 AM
Brenner Pieszak
Brenner Pieszak - avatar
4 Answers
+ 2
James Pink i just split the two input strings at the comma and then made them a list and did the operation list[0]*list[1]. It passed all the test cases so I think its good to go?
17th Oct 2020, 3:55 AM
Brenner Pieszak
Brenner Pieszak - avatar
+ 1
a = input().split() for i in range(len(a)): a[i]=int(a[i]) Use variable a which contains all elements as a number instead of str
17th Oct 2020, 12:17 AM
Ayush Kumar
Ayush Kumar - avatar
0
nevermind i got it you can delete thanks :D
17th Oct 2020, 12:15 AM
Brenner Pieszak
Brenner Pieszak - avatar
0
Brenner Pieszak Which solution did you go with? How does it handle unexpected input?
17th Oct 2020, 12:54 AM
James Pink
James Pink - avatar