Python - Read floating-point numbers

Introduction

To support input of floating-point numbers instead of just integers, run a float call and catch its exceptions:

Demo

while True: 
    reply = input('Enter text:') 
    if reply == 'stop': break 
    try: # w  ww .  j  a  v a2  s  .c om
        print(float(reply) ** 2) 
    except: 
        print('Bad!' * 8) 
print('Bye')

Result

Related Topic