I am getting TypeError: not all arguments converted during string formatting please help me how to debug

Hi, I am new to Python and from non programing backgroud. Just 1 week back i have started python online course and started practicing exercises. please help me by guiding me how to write a functions and how to decide what function needs to be used in what surcmstances.

also iam getting error for below code:

num = (input("Eenter a Number: "))
mod = (num) % 2
if mod > 0:
    print("is  odd number.")
else:
    print("is even number.")

error is : TypeError: not all arguments converted during string formatting

You’re missing a function call. Your second line should be

mod = int(num) % 2

Thank you its working now. But can you please tell me why we are using int there in second line

Because when you use input, the result is a string. In order to do arithmetic on the input value, you need to convert it to integer - or float if you want to use floating point arithmetic.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.