Demo entry 6363220

Challenge 6 - MaxMin

Submitted by anonymous on May 12, 2017 at 16:02
Language: Python. Code size: 2.1 kB.

```nums = []
minBoundary = input("Please enter a minimum boundary: (Type \'none\' if you don't want a minimum)")
maxBoundary = input("Please enter a maximum boundary: (Type \'none\' if you don't want a minimum)")
try:
minBoundary = int(minBoundary)
except ValueError:
pass

try:
maxBoundary = int(maxBoundary)
except ValueError:
pass

while True:

in_ = input("Please enter a number or valid keyword (type \'?\' for a list of keywords): ")
if in_ == "stop":
break
elif in_ == "quit":
raise SystemExit()
elif in_ == "?":
print("""
Valid keywords are:

╔════════╦═══════════════════════════════╗
║   stop ║ stop entering values and      ║
║        ║ display the min and max       ║
╠════════╬═══════════════════════════════╣
║   quit ║ quit the program              ║
╠════════╬═══════════════════════════════╣
║      ? ║ display this help.            ║
╚════════╩═══════════════════════════════╝
""")
else:
try:
in_ = int(in_)
if (minBoundary,maxBoundary)==('none','none'):
nums.append(in_)

elif minBoundary=='none' and maxBoundary!='none':
if in_ < maxBoundary:
nums.append(in_)
else:
print("Number is above max boundary of "+str(maxBoundary))

elif maxBoundary=='none' and minBoundary!='none':
if in_ > minBoundary:
nums.append(in_)
else:
print("Number is above max boundary of "+str(maxBoundary))

else:
if ( (in_ > minBoundary) and (in_ < maxBoundary) ):
nums.append(in_)
else:
print("Value outside of boundaries")

except ValueError:
print("Value not a number or valid keyword.")

nums = list(map(str,sorted(nums)))
print("Max number: "+nums[-1])
print("Min number: "+nums[0])
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.