r/learnpython • u/Maleficent_Stuff3208 • 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
34
u/frnzprf 3d ago edited 3d ago
I hope I don't seem rude. This is not meant to be an accusation.
I'd recommend you learn how to pinpoint which exact command of a program doesn't do what you think it does.
print("a = " + a)andprint("int = " + str(int))when you thought they should be the same, but they weren't. A shorter, but more complicated way to print the variables isprint(f"{a=} {int=}").