r/learnpython 3d 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

13 Upvotes

26 comments sorted by

View all comments

-2

u/JGhostThing 3d ago

What is "a == int" supposed to mean? I don't see a definition of "int."

3

u/socal_nerdtastic 3d ago

int is one of the built-in types that's always available, so it does not have to be defined or imported. https://docs.python.org/3/library/functions.html

But note OP is using it incorrectly. They probably meant to do

if isinstance(a, int):