0

Why the below code gets stuck after entering either int. or str in sublime text ? same code runs fine with python3 command line or pycharm.

print ('\n asks for an integer and prints the square of it\n')
def square(num):
    return num **2

def ask():
    while True:
        try:
            usr_input = int(input('Input an integer:'))
        except:
            print (f'An error occurred! Please try again!')
            continue
        else:
           return (f'Thank you, your number squared is:{square(usr_input)}')
print(ask())
busybear
  • 10,194
  • 1
  • 25
  • 42
cert77
  • 1

2 Answers2

-1
       return (f'Thank you, your number squared is:',square(usr_input))
print(ask())

You need to use square function like this. Hope it was helpful.

Naveen Kumar
  • 31
  • 1
  • 3
-1

Here is your Code just do one thing separate the square(usr_input)) and remove the curly brases

 print ('\n asks for an integer and prints the square of it\n')
def square(num):
    return num ** 2

def ask():
    while True:
        try:
            usr_input = int(input('Input an integer:'))
        except:
            print ('An error occurred! Please try again!')
            continue
        else:
            return ('Thank you, your number squared is:',square(usr_input))

print(ask())

Output-

asks for an integer and prints the square of it

Input an integer:5
('Thank you, your number squared is:', 25)