0

For some reason in the code, I was testing whether it would work with two numbers, but the a variable would be 2 once I typed it out, but the code said when I run it is that it is not 2. What is the problem? Also I used Pycharm if that's part of the problem.

def part1(Answer1, Answer2):
x=Answer1+Answer2
y=x/2
print(y)

print("What are your numbers? 2 max")
a=input("How many numbers would you like? :")
Answer1=input("What is your first number? :")
Answer2=input("What is your second number? :")

if a==2:
    part1(Answer1, Answer2)
else:
    print(a)
blackraven
  • 5,284
  • 7
  • 19
  • 45
curious
  • 13
  • 1
  • Please indent the code correctly. Python is dependent on indentation. – puncher Aug 09 '22 at 19:58
  • Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – Sören Aug 09 '22 at 20:02
  • Note that the number 2 and the string "2" print the same but are different values. – jarmod Aug 09 '22 at 20:03

1 Answers1

2

Because input() returns a string:

a=input("How many numbers would you like? :")
print(type(a)) # str

You need to convert it to the int (the same for Answer1 and Answer2):

a=int(input("How many numbers would you like? :"))
funnydman
  • 9,083
  • 4
  • 40
  • 55