Python Forum
beginner question about lists and functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner question about lists and functions
#6
There is shorter and arguably simple way to determine leap year:

if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:


Python first evaluates 'and' (which is first part of 'or' clause): is year divisible by four and not divisible by 100. If so - it's leap year (True). However, if 'and' evaluates to False second part of 'or' clause is evaluated which checks whether year is divisible by 400 (if year is divisible by 400 it is divisible by four as well)
sudonym3 likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: beginner question about lists and functions - by perfringo - Oct-17-2020, 12:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 221 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Need help with sorting lists as a beginner Realist1c 1 770 Apr-25-2023, 04:32 AM
Last Post: deanhystad
  A simple "If...Else" question from a beginner Serena2022 6 1,779 Jul-11-2022, 05:59 AM
Last Post: Serena2022
  Waiting for heavy functions question philipbergwerf 14 3,443 Apr-29-2022, 07:31 PM
Last Post: philipbergwerf
Question Beginner Boolean question [Guessing game] TKB 4 2,368 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,514 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,272 Mar-09-2021, 04:21 AM
Last Post: deanhystad
  Noob question about lists adifrank 4 2,918 Nov-19-2020, 03:26 AM
Last Post: adifrank
  Question about functions(built-in) Jinja2Exploitation 2 1,972 Nov-15-2020, 02:13 PM
Last Post: jefsummers
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,416 Sep-19-2020, 09:12 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020