max(), min() with raw_input and different outcomes in python -
i having trouble finding max , min code, can't calculate them, it's throwing inexact results when inputting data, example, not know why setting raw input int rather str code doesn't print correct result, though max or min calculates right when used solely list, , why letting to remain str code calculates right, sometimes, throws gross! different between setting raw inout int or remain string when relating max() or min(), why there such difference? , why int object not iterable in loop?
while true: x = raw_input('') if x == 'd': break try: v = x # or v = int(x) except: continue numbers = [] numbers.append(v) print max(numbers) print min(numbers)
while true: # ... numbers = []
numbers
assigned new empty list in every loop iteration. values thought stores lost. should put outside loop instead:
numbers = [] # move here while true: # ... numbers.append(v)
Comments
Post a Comment