Integer Input
age = int(input("Enter your age: "))
print("You are", age, "years old.")
Float Input
price = float(input("Enter the price: "))
print("The price is:", price
Basic Input (String)
name = input("Enter your name: ")
print("Hello, " + name + "!")
Format()
name = "Alice"
age = 25
print("My name is {} and I am {} years old.".format(name, age))
Output:
My name is Alice and I am 25 years old.
Using Indexed .format()
name = "Alice"
age = 25
print("My name is {0} and I am {1} years old.".format(name, age))
Output:
My name is Alice and I am 25 years old.
Using Named Placeholders in .format()
name = "Alice"
age = 25
print("My name is {n} and I am {a} years old.".format(n=name, a=age))
Output
My name is Alice and I am 25 years old.
sum of two numbers
# Taking two numbers as input
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Calculating sum
sum_result = num1 + num2
# Printing the result using f-string
print(f"The sum of {num1} and {num2} is {sum_result}")