Python - Doing Math on User Inputs

Introduction

We cannot raise a string of digits to a power unless we convert it manually to an integer:

Demo

while True: 
    reply = input('Enter text:') 
    if reply == 'stop': 
        break # from w  ww .ja va  2  s.c om
    elif not reply.isdigit(): 
        print('Bad!') 
    else: 
        print(int(reply) ** 2) 
print('Bye')

Result

Related Topic