0% found this document useful (0 votes)
2 views9 pages

Python Input and Output

The document provides an overview of the input() function in Python, explaining how to take user input and convert it to different data types such as integers and floats. It includes examples of single and multiple value inputs, as well as methods to store inputs in lists. Additionally, the document features a mini-quiz with multiple-choice questions related to Python programming and strings.

Uploaded by

swathy
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)
2 views9 pages

Python Input and Output

The document provides an overview of the input() function in Python, explaining how to take user input and convert it to different data types such as integers and floats. It includes examples of single and multiple value inputs, as well as methods to store inputs in lists. Additionally, the document features a mini-quiz with multiple-choice questions related to Python programming and strings.

Uploaded by

swathy
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

INPUT Value

PYTHON INPUT VALUES


1. What is input() in Python?
 input() is a built-in function used to take input from the user.
 The input is always stored as a string (text) by default.

Syntax:
variable = input("Message to user: ")

2. Single Value Input in Python


Example 1: Input a number
a = input("Enter a number: ")
print(a)

Output:
Enter a number: 10
10

👉 Here a is stored as string, not integer.

🔹 Convert Input to Integer


a = int(input("Enter a number: "))
print(a)

🔹 Convert Input to Float


b = float(input("Enter a decimal number: "))
print(b)
🔹 Input a String
name = input("Enter your name: ")
print(name)

3. Multiple Values Input in Python

Method 1: Using split()


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

Input:
10 20

Method 2: Convert Multiple Inputs to Integer using map()


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

Explanation:

 split() separates input


 map(int, ...) converts each value to integer

Method 3: Multiple Float Values


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

✅ 4. Input Multiple Values in List


numbers = list(map(int, input("Enter numbers: ").split()))
print(numbers)
Input:
1 2 3 4 5

Output:
[1, 2, 3, 4, 5]

✅ 5. Understand
 input() always returns string
 Use int() for integer input
 Use float() for decimal input
 split() separates multiple values
 map() converts multiple inputs to required datatype

✅ 6. Simple Assignment Example Program


# Single input
a = int(input("Enter one number: "))
print("Single value:", a)

# Multiple input
x, y = map(int, input("Enter two numbers: ").split())
print("Multiple values:", x, y)
print("Sum:", x + y)

Nice, Swathy. Time for a Python MCQ mini-quiz. Think of it like a brain gym for your code
neurons 🧠🐍

✅ 10 Python Program MCQs (with Code)


1️⃣What is the output?
a = 10
print(a)

A) 0
B) 10
C) a
D) Error

2️⃣What is the output?


print(type(5))

A) int
B) <class 'int'>
C) number
D) integer

3️⃣What is the output?


a = 5
b = 2
print(a + b)

A) 7
B) 52
C) 10
D) Error

4️⃣What is the output?


print(10 // 3)

A) 3.33
B) 3
C) 4
D) Error
5️⃣What is the output?
print(10 % 3)

A) 1
B) 3
C) 0
D) 10

6️⃣What is the output?


x = "10"
print(x)

A) 10 (integer)
B) "10" (string)
C) Error
D) None

7️⃣What is the output?


a = int("5")
print(a + 2)

A) 7
B) 52
C) Error
D) 5

8️⃣What is the output?


print("Python")

A) Python
B) "Python"
C) Error
D) None
9️⃣What is the output?
a = 3
b = 3
print(a == b)

A) True
B) False
C) 0
D) Error

🔟 What is the output?


print(2 * 3)

A) 5
B) 6
C) 23
D) Error

String

Nice, Swathy! Let’s dive into Python String MCQs. Strings are like necklaces of characters,
each bead a letter or symbol 🧵✨

10 Python MCQs Based on Strings

1️⃣What is the output?


s = "Python"
print(s)

A) Python
B) "Python"
C) Error
D) None

2️⃣What is the output?


s = "Hello"
print(s[1])

A) H
B) e
C) l
D) o

3️⃣What is the output?


s = "Python"
print(len(s))

A) 5
B) 6
C) 7
D) Error

4️⃣What is the output?


s = "Python"
print(s[0:3])

A) Pyt
B) Pyth
C) thon
D) Error
5️⃣What is the output?
s = "Hi"
print(s * 3)

A) HiHiHi
B) Hi 3
C) Error
D) HiHi

6️⃣What is the output?


s = "Python"
print([Link]())

A) python
B) PYTHON
C) Python
D) Error

7️⃣What is the output?


s = "HELLO"
print([Link]())

A) hello
B) HELLO
C) Hello
D) Error

8️⃣What is the output?


s = "Python"
print(s[-1])

A) P
B) n
C) y
D) Error
9️⃣What is the output?
s = "Hello World"
print([Link]())

A) Hello World
B) ['Hello', 'World']
C) Hello,World
D) Error

🔟 What is the output?


s = "Python"
print([Link]("P", "J"))

A) Jython
B) Python
C) Jyton
D) Error

✅ ANSWER KEY
[Link] Correct Answer
1 A
2 B
3 B
4 A
5 A
6 B
7 A
8 B
9 B
10 A

You might also like