python - How do I calculate min and max from a user input in python3 -
python - How do I calculate min and max from a user input in python3 -
def main(): print("*** high school diving ***") num_judges=int(input("how many judges there? ")) in range (num_judges): scores=int(input("ender score: " )) x=min(scores) y=max(scores) print("min: ", x) print("max: ", y) main()
you need utilize list, , append each entered score it:
scores = [] in range (num_judges): scores.append(int(input("enter score: " )))
max()
, min()
pick highest , lowest value respectively list.
what did, instead, replacing scores
new value each time looped; seek , find min()
of 1 integer, doesn't work:
>>> min(1) traceback (most recent phone call last): file "<stdin>", line 1, in <module> typeerror: 'int' object not iterable
by using list, min()
function can loop on (iterate) , find minimum value:
>>> min([1, 2, 3]) 1
python max min
Comments
Post a Comment