[Tutor] help with alternate execution

Patrick Sabin patrick.just4fun at gmail.com
Fri Oct 2 12:34:09 CEST 2009

  wrobl1rt at cmich.edu wrote:
> Thank you for the reply.. I tried putting the print repr(n)
> before I defined 'n' with raw_input. My script looks like
> this------
> def divisible(n):
>    if n%3 == 0:
>        print n, "is divisible by 3"
>    else:
>        print n, "is not divisible by 3"
> n= raw_input("enter a number= ")
> print repr(n)
> print divisible(n)

> I don't understand what the problem is

The problem is raw_input gives you a string. So in your example n is a 
string and when it comes to n%3 python tries to format your string, but 
since you haven't any formating symbols in it, it fails.

To fix your program, convert the n to int:


- Patrick

More information about the Tutor mailing list