0% found this document useful (0 votes)
3 views2 pages

Python Input Handling: Multiple Numbers

Uploaded by

hossainomar2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Input Handling: Multiple Numbers

Uploaded by

hossainomar2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

✅ Basic Way (with split()):

python
CopyEdit
a, b = input("Enter two numbers: ").split()

 This lets the user type two values with a space, like:
5 10
 a will get 5, and b will get 10

⚠️But these are still strings. So if you want them as numbers, do this:

🔢 With int() (if inputs are numbers):


python
CopyEdit
a, b = map(int, input("Enter two numbers: ").split())

 Example input:
7 12
 Then a will be 7 (int), and b will be 12 (int)

📌 If you want float numbers:


python
CopyEdit
x, y = map(float, input("Enter two decimal numbers: ").split())

🧪 Example program:
python
CopyEdit
x, y = map(int, input("Enter two numbers: ").split())
print(f"The sum is: {x + y}")

Let me know if you want to take 3 or more inputs the same way! 😄

4o

You said:

yes
ChatGPT said:

Awesome! 😄 Taking 3 or more inputs at once in Python is just as easy.

✅ Example: Taking 3 integers from the user


python
CopyEdit
a, b, c = map(int, input("Enter three numbers: ").split())

 Example input from user:


5 10 15
 Now:
o a = 5
o b = 10
o c = 15

✅ For 4 or more:

Just add more variables:

python
CopyEdit
w, x, y, z = map(int, input("Enter four numbers: ").split())

🔁 If you want any number of inputs (as a list):


python
CopyEdit
numbers = list(map(int, input("Enter numbers: ").split()))

 Example input: 3 6 9 12 15
 Output: numbers = [3, 6, 9, 12, 15]

💡 Tip:

Always remind users to separate inputs with spaces, not commas. (Unless you're using
.split(','))

You might also like