how can we enter 2 numbers? ı can enter only 1 number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how can we enter 2 numbers? ı can enter only 1 number

13th Jul 2016, 7:47 AM
Muhammed Atıf Karadağ
Muhammed Atıf Karadağ - avatar
7 Answers
+ 3
There are several ways to do it, Andrzej Wojtus, depending on what you want to do. A simple program could be: print('Type a number: ') number1 = int(input()) print('Type a second number: ') number2 = int(input()) print(str(number1 + number2)) This program will ask the user to type two values. Python will storage this values in the variables «number1» and «number2», respectively. You use the int() and str() functions to convert the data type of each values. This is because the input() function always takes String data types (even if you type numbers). So, you first tell Python that number1 value and number2 values are Integers data types, that way Python can 'add' both numbers. Finally, you have to make one last conversation to String again when you call the last print() function.
26th Jul 2016, 8:22 PM
Francisco Gómez García
Francisco Gómez García - avatar
+ 2
try with: first_number = int(input("Enter first number")) second_number = int(input("Enter second number"))
13th Jul 2016, 10:03 AM
RedAnt
RedAnt - avatar
+ 2
I reckon u were talking about the second example in type-conversation. To input 2 number, you just need to enter 2 number at the same time with a " "(space) to separate them. wish I could help.
15th Jul 2016, 5:36 AM
A.L
A.L - avatar
0
Base on what your saying, that you can only input one value... It depends on where you are running the program. The interactive shell is good to run Python instructions one at a time (as soon as you press ENTER). To type an entire program you have to use the file editor.
13th Jul 2016, 10:57 AM
Francisco Gómez García
Francisco Gómez García - avatar
0
You can prompt the user to enter multiple values in one line and use split(' ') to get a list that you can then convert to int etc.
13th Jul 2016, 3:04 PM
Brad McLennan
0
thank you guys
15th Jul 2016, 6:29 AM
Muhammed Atıf Karadağ
Muhammed Atıf Karadağ - avatar
0
Could someone do an example of this? I'm new to this and trying to figure it out, but still can't. I'm doing exactly as the example shows and still can't figure it out.
26th Jul 2016, 6:39 PM
Andrzej Wojtus
Andrzej Wojtus - avatar