New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Newbie question: Python 3 calculations using input
Hi! New here. I have a question regarding Python 3 basics. I'm trying to understand how I can use the input function for simple calculations. What I tried to do is to set up a simple line where I can input 2 digits and let Python add them together for me. Here's what I tried: 1. print(input() + input()) 2. print (input("") + input("")) When I then add the numbers 2 and 3 as an input, I get 23 as the result. How do I have to change the code to get 5? Thanks for your help! I'm eager to learn. Marc
2 Answers
+ 2
Input() returns string ,so "2"+"3" is 5 ,convert input into int like
int(input())
+ 2
Here's what you need to do :
num1 = int(input())
num2 = int(input())
print(num1 + num2)