how can we enter 2 numbers? ı can enter only 1 number | Sololearn: Learn to code for FREE!

0

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

7/13/2016 7:47:39 AM

+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.

+2

try with: first_number = int(input("Enter first number")) second_number = int(input("Enter second number"))

+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.

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.

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.

0

thank you guys

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.