How to get input from the user in Python:
Basic Input Example (String Concatenation):
a = input("Enter the first string: ") b = input("Enter the second string: ") c = a + b print(c)
Explanation:
Step 1: The variable a
stores the first string entered by the user.
Step 2: The variable b
stores the second string entered by the user.
Step 3: The two strings stored in a
and b
are concatenated and stored in c
.
Step 4: The result stored in c
is printed.
Example (User's Input and Output):
Enter the first string: Hello Enter the second string: World # Output after concatenation: HelloWorld
Input with Integer Conversion (Addition of Numbers):
a = int(input("Enter number A value: ")) b = int(input("Enter number B value: ")) c = a + b print(c)
Explanation:
Step 1: The variable a
stores the first number entered by the user, which is converted to an integer.
Step 2: The variable b
stores the second number entered by the user, which is converted to an integer.
Step 3: The two integers stored in a
and b
are added, and the result is stored in c
.
Step 4: The result stored in c
is printed.
Example (User's Input and Output):
Enter number A value: 5 Enter number B value: 3 # Output after addition: 8
0 Comments