Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: TypeError: unorderable types: function() < int() Date: Tue, 10 May 2016 08:19:05 -0400 Organization: IISS Elusive Unicorn Lines: 139 Message-ID: References: <1fc32599-0264-460c-8178-057558d19be5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de CZ636iNMpYQIB1bjhTAO5APavWRT1tGjJfobO6TrNZ/w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'used.': 0.05; 'computed': 0.07; 'argument,': 0.09; 'default:': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'subtract': 0.09; 'thrown': 0.09; 'wrong,': 0.09; 'python': 0.10; 'itself.': 0.11; '2.7': 0.13; 'syntax': 0.13; 'argument': 0.15; 'value.': 0.15; '(either': 0.16; '(int)': 0.16; '11:59:59': 0.16; '2016': 0.16; 'boundary:': 0.16; 'declaration': 0.16; 'early.': 0.16; 'nearest': 0.16; 'programmer,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'time.time()': 0.16; 'string': 0.17; '"you': 0.18; 'comparing': 0.18; 'integer': 0.18; 'numerical': 0.18; 'result,': 0.18; 'url:home': 0.18; 'programmer': 0.18; 'input': 0.18; "aren't": 0.22; 'clock': 0.22; 'delta': 0.22; 'please?': 0.22; 'pass': 0.22; 'code,': 0.23; 'code.': 0.23; 'defined': 0.23; '(or': 0.23; 'second': 0.24; 'tried': 0.24; 'import': 0.24; 'wondering': 0.25; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'error': 0.27; 'define': 0.27; 'issue,': 0.27; 'function': 0.28; 'away.': 0.29; 'end,': 0.29; 'invoke': 0.29; 'long.': 0.29; 'referencing': 0.29; 'second,': 0.29; 'character': 0.29; "i'm": 0.30; 'print': 0.30; 'code': 0.30; 'seconds': 0.31; 'supposed': 0.31; 'statement': 0.32; 'run': 0.33; 'point': 0.33; 'problem': 0.33; '-0700': 0.33; 'tue,': 0.34; 'previous': 0.34; 'gets': 0.35; 'skip:c 30': 0.35; 'could': 0.35; 'attempt': 0.35; 'direction': 0.35; 'formats': 0.35; 'comment': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'possible': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'say': 0.37; 'received:org': 0.37; 'charset:us- ascii': 0.37; "won't": 0.38; 'anything': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'end': 0.39; 'means': 0.39; 'format': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'field': 0.60; 'ten': 0.60; 'save': 0.60; 'your': 0.60; 'press': 0.61; 'per': 0.62; 'more': 0.63; 'different': 0.63; 'day.': 0.63; 'times': 0.63; 'other.': 0.64; 'believe': 0.66; 'here': 0.66; 'friend': 0.81; '(hint:': 0.84; '>def': 0.84; '>if': 0.84; 'again!': 0.84; 'checker': 0.84; 'expect.': 0.84; 'milliseconds': 0.84; 'mistakes.': 0.84; 'processed,': 0.84; 'dennis': 0.91; 'fast!': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-68-176-146.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <1fc32599-0264-460c-8178-057558d19be5@googlegroups.com> Xref: csiph.com comp.lang.python:108461 On Tue, 10 May 2016 02:01:45 -0700 (PDT), George Molsom declaimed the following: > >The following are the code I currently have and the error produced when I attempt to run it. I have tried everything I can think of to resolve the issue, and I have also run the code through a checker, which has said that there are no mistakes. I have also shown a friend who is a programmer, and he cannot find a problem with it. The teacher doesn't actually know the solution to the problem so I was wondering if someone could point me in the right direction to get this working please? > Really -- neither the instructor nor a programmer can find any problems in the code sample? I count ten problems minimum, just scanning the code. A checker won't find anything since every statement is valid Python syntax -- it just doesn't do what you expect. > > >import time > >def second(int): > time.strftime("%S") > You declare "second" as a function taking one argument, but you never use the argument (hint: (int) is not a declaration of a return type). #1 You invoke strftime() [in default: use current time mode], but pass it a format that is not defined in the documentation (or wasn't in Python 2.7 which I'm still running). #2 %s (lowercase) formats the seconds field of the time of day. And worst, since you don't return the result, it just gets thrown away. #3 Good thing you never call your second() function. #I won't count that >start = input('Press enter when you are ready to start') >time1 = time.strftime("%S") > This time you save the string form of the seconds of the time-of-day >then = time.time() > And here you actually get numerical clock value. Of course, a few milliseconds may have passed while the previous statement was processed, so this time will be different from the time used in strftime(). >end = input('Press enter when you think 10 seconds has passed') >time2 = time.strftime("%S") > Same comment as under "start" >def totaltime(int): > (time2-time1) > Again you define a function with an input argument which is not used. #4 time2 and time1 are STRINGS; you can not subtract them from each other. #5 They are also only the second field from a time-of-day which means it is possible that they crossed over a minute boundary: TOD1 11:59:59 time1 59 TOD2 12:00:09 time2 9 time2 - time1 -50 #6 Again you do not return the value computed in totaltime, so it is not available for other uses later. #7 >if totaltime == '10': As explained by others, you aren't calling totaltime, you are only referencing the function object itself. #8 You are also expecting it to return a character string rather than a number, since it is a character string you are comparing against. > print ('YOU ACTUALLY DID IT') > >if totaltime < 10: This time you are comparing against an integer value... Which is it supposed to be #9 (either the character is wrong, or the integer is wrong) > print ('Haha you took too long! Your result was:', totaltime,'seconds') > If the "player" took LESS THAN 10 seconds you print that they too too long. #10 >if totaltime > 10: > print('Too early TRY AGAIN! Your result was:', totaltime, 'seconds') > And if they took more than 10 seconds you say they were too early. #not counted You also attempt to call totaltime 5 times in that section of code, even though the result won't change. #not counted -=-=-=-=- # Python 2.7 syntax used import time raw_input("Press [enter] to start timing") #throw out input strt = time.time() raw_input("Press [enter] when you believe 10 seconds have passed") end = time.time() delta = end - strt # strt, end, and delta are floats, per the documentation # so round it to the nearest second, and make it integer seconds = int(round(delta)) if seconds < 10: print "You were too fast! Your time was %s seconds" % seconds elif seconds > 10: print "You were too slow! Your time was %s seconds" % seconds else: print "You were on 10 seconds (give or take half a second)" -=-=-=-=- {Not really a "reaction timer" but only name I could come up with at the moment} C:\Users\Wulfraed\Documents\Python Progs>reactionTimer.py Press [enter] to start timing Press [enter] when you believe 10 seconds have passed You were too slow! Your time was 12 seconds C:\Users\Wulfraed\Documents\Python Progs>reactionTimer.py Press [enter] to start timing Press [enter] when you believe 10 seconds have passed You were too fast! Your time was 8 seconds C:\Users\Wulfraed\Documents\Python Progs> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/