
User Input in Python
The primary tool for user input in Python is the input() function. It pauses your program's execution and waits for the user to type something. Whatever the user types is returned as a string by the input() function.
user_input = input("Enter your name: ")
This code displays the prompt "Enter your name: " on the screen. The user types their name and presses Enter. The program then stores the entered name in the variable user_input.
name = input("What's your name?")
print("Hello, " + name + "!")
This program asks the user for their name and then prints a personalized greeting.
2. Getting Numbers from the User:
age = int(input("How old are you? "))
print("You are", age, "years old.")
Here, the program asks for the user's age. However, input() always returns a string. We use int() to convert the entered string to an integer before storing it in the age variable.
p = int(input("Enter the marks of physics:"))
c = int(input("Enter the marks of chemistry:"))
m = int(input("Enter the marks of math:"))
b = int(input("Enter the marks of biology:"))
s = p+c+m+b
a=(p+c+m+b)/5
print("Total=",s)
print("average=",a)
b = int(input("enter the base length"))
h = int(input("enter the height"))
s = int(input("enter the slant height"))
B = float(b*b)
S = float((2*b*s)+(b*b))
V = float(b*b*h/3)
print("base area=", B)
print("surface area=", S)
print("volume=", V)