Simple Python - Error in Programming -
i've been stuck on issue on 2 hours, homework please don't give me direct answer point me in right direction.
so... program designed input "speed limit", input "current speed" , give print response of either "speed ok" (if below or equal speed limit) , "slow down!" (if speeding). when input following data, required on task: speed limit of 50. current speed of 50, 45, 55, 52, , 50.
the answer should read -
speed limit: 50 current speed: 50 speed ok current speed: 45 speed ok current speed: 55 slow down! current speed: 52 slow down! current speed: 50 speed ok current speed:(white space)
instead -
current speed: 50 speed ok current speed: 45 *then program stops.*
my program reads -
limit = int(input("speed limit: ")) speed = int(input("current speed: ")) if speed <= limit: print("speed ok") speed = int(input("current speed: ")) false = speed > limit while false: print("slow down!") speed = int(input("current speed: "))
if point me in right direction wonderful ;).
cheers,
ron
first of all, keep in mind 1 of important rules of programming avoid code doubling. means never idea have same speed = int(input("current speed: "))
line 3 times in program. if there's error in line, fixing leave error in 2 other places untouched.
if follow rule, find out need 1 loop should terminate on (white space)
(so check should in condition, not false
). , inside loop should check if
response program should give.
finally, strongly disapprove of having variable named false
. in case speed
larger limit
, variable false
hold value true
(which quite peculiar , surprising). other programmer misunderstand this.
never forget writing program communicating next programmer has maintain code.
Comments
Post a Comment