0

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()
MPelletier
  • 16,256
  • 15
  • 86
  • 137
Suliman Sharif
  • 607
  • 1
  • 9
  • 26

3 Answers3

4

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?)

Danica
  • 28,423
  • 6
  • 90
  • 122
  • It says traceback(most recent call last): File "EasterSunday.py". line 69 in main and then File "EasterSunday.py", line 24, in main a = y % 19. TypeError: not all arguments converted during string formatting – Suliman Sharif Jun 30 '13 at 18:00
  • Ah, that's only the one error! It's just showing you where the problem was located. – Danica Jun 30 '13 at 18:09
  • Okay so I tried changing the int in the year to enter but unfortunately now everything comes out as a decimal which I didn't want I tried putting int(input for the formulas but that didn't work. So it just won't now print the rest of my code correctly. – Suliman Sharif Jun 30 '13 at 18:14
  • Use `b = y // 100` to have it round the result down rather than put it as a decimal. Alternatively, you could use `b = int(y / 100)` if you wanted. – Danica Jun 30 '13 at 19:17
1

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.

Community
  • 1
  • 1
Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
0
~$ 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
thefourtheye
  • 233,700
  • 52
  • 457
  • 497