+ 2

What do i do with multiple inputs in a code

For example 52 and 64 as inputs How do I interger them

24th Dec 2022, 3:47 PM
Something
5 Answers
+ 7
Something , there is a procedure that can prevent unacceptable inputs. we can take input as string (this the default) and check it in the second step with the string function .isdigit(). if all characters of the input string are digits, the function returns True, otherwise False. num1 = input() if num1.isdigit(): # if all characters are digits num1 = int(num1) # convert the input to string print('input is an integer:', num1) else: print('error, input not an integer', repr(num1))
24th Dec 2022, 4:57 PM
Lothar
Lothar - avatar
0
You can use inputs to perform actions in your program. To make sure the input is an integer, int() function can be used. If the input is not a data type of an integer, it will execute an error. You can see the code below, I just made that creates a function and uses user's input to perform a calculation. It's all explained. I do not know whether or not you can change it, or input anything, but here it is: https://code.sololearn.com/c83lAiHzpysv/?ref=app
24th Dec 2022, 3:58 PM
Lamron
Lamron - avatar
0
by using the int() fuction
24th Dec 2022, 4:25 PM
Chris Jonathan
Chris Jonathan - avatar
0
When you take input in python it is normally stored as a string. 1 option would be to re-assign it as an int value. So for example a = input() a = int(a) The 2nd option would be to assign the input as an integer to begin with... a = int(input())
24th Dec 2022, 8:32 PM
Alexander Kerr
Alexander Kerr - avatar
0
In Solo learn, Multiple inputs can be separated by whitespaces. But hear me out. Going with the same logic, you can store the input in a list by performing split(' ') on the input string. And convert to respective data types. # Example input_data = input("Separate multiple inputs by whitespaces").split(' ') name = input_data[0] age = int(input_data[1]) print(name + ' is ', age, ' year(s) old')
25th Dec 2022, 6:19 PM
Mukarrabeen Khan
Mukarrabeen Khan - avatar