Python Problems -
hey guys i'm having problem python question.
a formula computing easter in years 1982 – 2048
, inclusive, follows:
let
a = year %19 b = year %4 c = year % 7 d = (19a + 24)%30 e= (2b + 4c + 6d + 5) % 7
the date of easter march 22 + d + e
(which in april). write program inputs year, verifies in proper range, , prints out date of easter year. additionally, write function easterii() this. function accepts no parameter , returns value. use return statement.
this code have currently. when enter in date outputs "there problem, try again."
any input appreciated, thanks.
def eastercal(year): = year % 19 b = year % 4 c = year % 7 d = ((19 * a) + 24) % 30 e = ((2 * b) + (4 * c) + (6 * d) + 5) % 7 date = 22+d+e return date def easterii(): try: year = eval(input('please enter year: ')) year = int(year) if year < 1982: print("year out of range") elif year > 2048: print("year out of range") else: date = eastercal(year) if 22 <= date <= 31: print('easter date year {0} march,{1}'.format(year , date)) elif 32 <= date <= 56: print('easter date year {0} april,{1}'.format(year,date-31)) else: print('incorrect.') except nameerror: print('please enter date in numbers') except: print('there problem, try again.') if __name__ == '__main__': easterii()
one problem in line:
year = eval(input('please enter year: '))
why using eval
? use year = int(input('please enter year: '))
. if enter year correctly, code work (i tested it).
Comments
Post a Comment