• Python question of the day

    What would be the output of executing the following code:
    print([n for n in range(1895, 1905) if (not(bool(n%4)) \
    and (bool(n%100) or not bool(n%400)))])
     [1896, 1904]
     [1896, 1900]
     [1896, 1900, 1904]
     ValueError
    Explanation:
    range(1895, 1905) gives [1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904] and the code finds leap years among these years (leap year has to be evenly divided by 4 for non century years and by 400 for century years, so 1900 is not leap year, but 2000 is leap year)


    Top 100 python interview questions:






datai analytics