Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108461
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: TypeError: unorderable types: function() < int() |
| Date | 2016-05-10 08:19 -0400 |
| Organization | IISS Elusive Unicorn |
| Message-ID | <mailman.562.1462882760.32212.python-list@python.org> (permalink) |
| References | <1fc32599-0264-460c-8178-057558d19be5@googlegroups.com> <d2i3jbdr1j3uihacv9m5boo5f161f8qnh4@4ax.com> |
On Tue, 10 May 2016 02:01:45 -0700 (PDT), George Molsom
<georgieelize00@gmail.com> 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/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
TypeError: unorderable types: function() < int() George Molsom <georgieelize00@gmail.com> - 2016-05-10 02:01 -0700
Re: TypeError: unorderable types: function() < int() Ben Finney <ben+python@benfinney.id.au> - 2016-05-10 19:16 +1000
Re: TypeError: unorderable types: function() < int() Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-05-10 08:19 -0400
Re: TypeError: unorderable types: function() < int() Chris Angelico <rosuav@gmail.com> - 2016-05-10 22:31 +1000
Re: TypeError: unorderable types: function() < int() Steven D'Aprano <steve@pearwood.info> - 2016-05-10 23:40 +1000
Re: TypeError: unorderable types: function() < int() Chris Angelico <rosuav@gmail.com> - 2016-05-10 23:47 +1000
Re: TypeError: unorderable types: function() < int() Steven D'Aprano <steve@pearwood.info> - 2016-05-10 23:55 +1000
Re: TypeError: unorderable types: function() < int() Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-05-10 19:57 -0400
csiph-web