Suliman Sharif
Suliman Sharif

Reputation: 607

Basic python programming

I don't know what is wrong. I tells me I have a string formatting error where a = y % 19 and then it also tells me I have something wrong with the module when I am calling the main(). No clue on how to fix this because it seems I am calling the main() function correctly and the string seems fine.

def main():

    y = input("Enter year: ")
    print ("y = ", y)

    a = y % 19
    print ("a = ", a)

    b = y / 100
    print ("b = ", b)

    c = y % 100
    print ("c = ", c)

    d = b / 4
    print ("d = ", d)

    e = b % 4
    print ("e = ", e)

    g = (8 * b + 13) / 25
    print ("g = ", g)

    h = (19 * a + b - d - g + 15) / 30
    print ("h = ", h)

    j = c / 4
    print ("j = ", j)

    k = c % 4
    print ("k = ", k)

    m = (a + 11 * h) / 319
    print ("m = ", m)

    r = (2 * e + 2 * j - k - h + m + 32)  % 7
    print ("r = ", r)

    n = (h - m + r + 90) / 25
    print ("n = ", n)

    p = (h - m + r + n + 19) % 32
    print ("p = ", p)

    print ("In ", y, "Easter Sunday is on", p,)
    if (n == 3):
        print ("March")
    if (n == 4):
        print ("April")

main()

Upvotes: 0

Views: 158

Answers (3)

Vivek Jain
Vivek Jain

Reputation: 3889

input() returns a string. You may like to convert it to an int as x = int(input(...))

You may like to use raw_input() also if you're using Python v2.x, which also returns string but does not evaluate any expression.

Check here for more details.

Upvotes: 1

thefourtheye
thefourtheye

Reputation: 239683

~$ python3 Test.py
Enter year: 2013
y =  2013
Traceback (most recent call last):
  File "Test.py", line 51, in <module>
    main()
  File "Test.py", line 6, in main
    a = y % 19
TypeError: not all arguments converted during string formatting

~$ python2.7 Test.py
Enter year: 2013
('y = ', 2013)
('a = ', 18)
('b = ', 20)
('c = ', 13)
('d = ', 5)
('e = ', 0)
('g = ', 6)
('h = ', 12)
('j = ', 3)
('k = ', 1)
('m = ', 0)
('r = ', 4)
('n = ', 4)
('p = ', 7)
('In ', 2013, 'Easter Sunday is on', 7)
April

Upvotes: 0

Danica
Danica

Reputation: 28856

It seems like you're using Python 3. If so, the first problem is that y is a string (like "2013"), not a number (like 2013). The % operation means something different for strings than it does for numbers; you'll have to convert y to an integer by saying y = int(input('....')).

Not sure what the problem with the module is; can you post the exact error message and the way that you're running the code? (Is it in IDLE, by calling python myscript.py, or what?)

Upvotes: 4

Related Questions