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 #  ww w  . ja v a  2  s  .  c o m
    elif not reply.isdigit(): 
        print('Bad!') 
    else: 
        print(int(reply) ** 2) 
print('Bye')

Result

Related Topic