x1=input("Enter first number: ")
x2=input("Enter second number: ")
print("Total :",x1+x2)
Output
Enter first number: 3
Enter second number: 4
Total : 34
Why the output is not equal to 7 with input of 3 and 4 as input numbers ? x1=int(input("Enter first number: "))
x2=int(input("Enter second number: "))
print("Total :",x1+x2)
Output
Enter first number: 3
Enter second number: 4
Total : 7
x1=float(input("Interest Rate is : "))
print ("interest rate ",x1)
Output
Interest Rate is : 5.6
interest rate 5.6
sum=0
for i in range(3):
x1=int(input('Enter a number'))
sum=sum+x1
print("Sum : ", sum)
def get_number(message):
while True:
user_input = input(message)
try:
number = float(user_input)
return number
except ValueError:
print("Invalid input. Please enter a number only.")
num1 = get_number("Enter first number: ")
num2 = get_number("Enter second number: ")
total = num1 + num2
print("The sum is:", total)
Try running the code and enter 30.4 as the first number and 50.3 as the second number. Then, analyze the output.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.