私はあなたがこのようなものが欲しいと思います:
# Show the startup message
print "Enter numbers, stops when negative value is entered:"
# This is the list of numbers
numbers = []
# Loop continuously
while True:
try:
# Get the input and make it an integer
num = int(raw_input("value: "))
# If a ValueError is raised, it means input wasn't a number
except ValueError:
# Jump back to the top of the loop
continue
# Check if the input is positive
if num < 0:
# If we have got here, it means input was bad (negative)
# So, we break the loop
break
# If we have got here, it means input was good
# So, we append it to the list
numbers.append(num)
# Show the maximum number in the list
print "Maximum is", max(numbers)
デモ:
数値を入力し、負の値を入力すると停止します:
値: 5
値: 9
値: 2
値: 4
値: 8
値: -1
最大は 9 です