0
I cant seem to get to turn the strings into an integer for a simple calculator
number_1 = input(56) number_2 = input(45) func = add if func == add: print (number_1 + number_2 ) It is something like this
3 Answers
+ 5
Please tag the relevant programming language.
In Python you can use int() to convert to integer.
What is "add" in your example?
+ 3
You should take a(nother) look at the section about functions in the Python Beginner course. In particular the part about creating your own functions.
+ 3
if you want to add 2 input without using function, correct your code like thatđ
1.
number_1 =56
number_2=45
print (number_1 +number_2)
2.if you want to get data from user... without using function
number_1 =int(input())
number_2=int(input())
print (number_1 +number_2)
3.If you want to use function
def add(n1,n2):
return n1+n2
num1=int(input())
num2=int (input())
print("sum is:" ,add (num1,num2))
#hope this helps