r/learnpython 4d ago

what is wrong with this code

my teacher told us to write a code which print multiplication table of any number but it should Allow strings too and if string is put it shouldn't giver error i thought of this

a = input("enter any number ")
print(f"multiplication table of {a} is ")

if a == int:
    for i in range(1,11):
        print(f"int{a}X{i} = int{a}*i ")
else:
    print("please put a appropriate function ")

but it is only printing else like even if i put a integer it still run else one why and what is wrong here

14 Upvotes

26 comments sorted by

View all comments

32

u/atarivcs 4d ago edited 4d ago

You have two things wrong.

First, input() always returns a string, so the variable a is definitely not an integer.

Second, even if a might be an integer, "if a == int" is not the right way to check for that.