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: #   ww w .  j a  v a 2s  . c  o  m
        print(float(reply) ** 2) 
    except: 
        print('Bad!' * 8) 
print('Bye')

Result

Related Topic