Python question Define a function, can_ride (height, with _ adult). It takes a f
ID: 3837479 • Letter: P
Question
Python question
Define a function, can_ride (height, with _ adult). It takes a floating point height and a bool value with_ adult to the check whether a child can ride the ride. If the child's height is greater than 42 inches, return True (allow the ride). If the child's height is great than 36 inches but not greater than 42 inches, allow the ride only if the child is with an adult Children with a height not greater than 36 inches cannot take the ride, Examples: can _ ride (45.4, False) rightarrow True can _ ride (40.0, False) rightarrow False can _ ride (40.0, True) rightarrow True can _ ride (30.3. True) rightarrow False def can _ ride (height, with _ adult):Explanation / Answer
def can_ride(height,with_adult):
if height > 36:
if height < 42:
if with_adult == 1:
return true
else:
return false
else:
return true
else:
return false
def main():
ret = can_ride(45.4,False)
if ret == 1 :
print "True"
else:
print "False"
ret = can_ride(40.0,False)
if ret == 1 :
print "True"
else:
print "False"
ret = can_ride(40.0,True)
if ret == 1 :
print "True"
else:
print "False"
ret = can_ride(30.3,True)
if ret == 1 :
print "True"
else:
print "False"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.