-1

As I've progressed a little more in Python I thought I would try out the define function. I've made this simple square root calculator. Please explain as simple as you can?

import math

def mathprob(x):
    math.sqrt(x)

yn = input()
num = int(input("Enter number to be square rooted."))

if yn == 'sqrt':
    ans = mathprob(num)
    print(ans)

elif yn == '':
    print("bye! :(")
    quit()
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
user2340615
  • 171
  • 3
  • 4
  • 10

2 Answers2

3

You need to return the value from your function, otherwise it returns None:

def mathprob(x):
     return math.sqrt(x)
mgilson
  • 300,191
  • 65
  • 633
  • 696
1

You need to actually return something from your function, you can do it like this:

def mathprob(x):
    return math.sqrt(x)
Mezgrman
  • 876
  • 6
  • 11