Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
odd or even minute
#8
(Dec-27-2019, 09:20 PM)Dixon Wrote: This thing is nutty. Again, it is not giving me the proper output. Now it is returning 'Not an odd minute' even though it is. It's an exercise from 'Head First Python'.

When I enter it with Visual Studio, it works. ??? I was using Python's Idle, and that is where the trouble seems to be.

Why don't you use code provided in the exercise? In the exercise there is (not that this is a good idea to use Python as typewriter):

odds = [1, 3, 5, 7, 9,11,13,15,17,19, 
       21,23,25,27,29,31,33,35,37,39, 
       41,43,45,47,49,51,53,55,57,59]
One will get different results depending whether 'odds' is assigned without brackets in one line or not.

I understand that this exercise about for-loop and if...else but desired result can be achieved without them as well:

datetime.today().minute % 2 and 'This is an odd minute' or 'This is an even minute'
As already pointed out by ndc85430 there is no point of defining list with odd values - it can be checked with % 2. However, if one absolutely needs this it can be done with much less typing:

>>> nums = range(1, 60, 2)                                           
>>> 31 in nums                                                       
True
>>> 30 in nums                                                       
False
>>> list(range(1, 60, 2))
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
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
odd or even minute - by Dixon - Dec-27-2019, 04:12 PM
RE: odd or even minute - by ndc85430 - Dec-27-2019, 04:31 PM
RE: odd or even minute - by Dixon - Dec-27-2019, 07:27 PM
RE: odd or even minute - by stullis - Dec-27-2019, 07:40 PM
RE: odd or even minute - by Dixon - Dec-27-2019, 09:20 PM
RE: odd or even minute - by perfringo - Dec-28-2019, 11:04 AM
RE: odd or even minute - by ndc85430 - Dec-28-2019, 07:16 AM
RE: odd or even minute - by Gribouillis - Dec-28-2019, 07:22 AM
RE: odd or even minute - by ibreeden - Dec-28-2019, 11:12 AM
RE: odd or even minute - by Dixon - Dec-28-2019, 05:07 PM
RE: odd or even minute - by perfringo - Dec-28-2019, 09:22 PM
RE: odd or even minute - by Dixon - Dec-29-2019, 04:58 PM
RE: odd or even minute - by Larz60+ - Dec-31-2019, 09:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Having trouble with minute stock data MAZambelli4353 2 2,413 Sep-03-2019, 09:41 AM
Last Post: perfringo
  python crontab remove_all(comment="Minute*") vvarrior 1 2,852 Aug-06-2018, 12:39 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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