File: LP6E/Chapter10/interact.py
# Note: triple quotes around versions here disables them.
# Remove quotes to test a specific version in this file.
# Version 1
"""
while True:
reply = input('Enter text:')
if reply == 'stop': break
print(reply.upper())
"""
# Sidebar alternative
"""
while (reply := input('Enter text:')) != 'stop':
print(reply.upper())
"""
# Version 2
"""
while True:
reply = input('Enter text:')
if reply == 'stop': break
print(int(reply) ** 2)
print('Bye')
"""
# Version 3
"""
while True:
reply = input('Enter text:')
if reply == 'stop':
break
elif not reply.isdigit():
print('Bad!' * 8)
else:
print(int(reply) ** 2)
print('Bye')
"""
# Version 4
"""
while True:
reply = input('Enter text:')
if reply == 'stop': break
try:
num = int(reply)
except:
print('Bad!' * 8)
else:
print(num ** 2)
print('Bye')
"""
# Version 5
"""
while True:
reply = input('Enter text:')
if reply == 'stop': break
try:
print(int(reply) ** 2)
except:
print('Bad!' * 8)
print('Bye')
"""
# Version 6
"""
while True:
reply = input('Enter text:')
if reply == 'stop': break
try:
print(float(reply) ** 2)
except:
print('Bad!' * 8)
print('Bye')
"""
# Version 7
while True:
reply = input('Enter text:')
if reply == 'stop':
break
elif not reply.isdigit():
print('Bad!' * 8)
else:
num = int(reply)
if num < 20:
print('low')
else:
print(num ** 2)
print('Bye')