python - Division by Zero Errors -



python - Division by Zero Errors -

mann have problem question professor. here question:

write definition of function typing_speed , receives 2 parameters. first number of words person has typed (an int greater or equal zero) in particular time interval. sec length of time interval in seconds (an int greater zero). function returns typing speed of person in words per min (a float ).

here code:

def typing_speed(num_words,time_interval): if(num_words >= 0 , time_interval > 0): factor = float(60 / time_interval) print factor homecoming float(num_words/(factor))

i know "factor" getting assigned 0 because not beingness rounded or something. dont know how handle these decimals properly. float isnt doing apparently.

any help appreciated, thankyou.

when phone call float on partition result, it's after fact partition treated integer partition (note: python 2, assume). doesn't help, help specify partition floating-point division, illustration saying 60.0 (the float version of 60):

factor = 60.0 / time_interval

another way split 60 float(time_interval)

note sample interaction:

in [7]: x = 31 in [8]: 60 / x out[8]: 1 in [9]: 60.0 / x out[9]: 1.935483870967742

python floating-point decimal division

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -