0

New to coding, started writing python yesterday, I’m trying to make a code for the area of a circle.

pi=3.14 
radius=input("enter radius here") 
print("area="+str(pi*(radius**2))) 

When I ran the code, it gave me a type error saying that unsupported operand type(s) for ** or pow(): 'str' and 'int.' I don’t understand what this means, can someone help me write it?

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
  • 2
    Complete shot in the dark: the tutorial says something like `x = input("Enter a number"); print(x**2)`. This code works in Python 2.7, but not in Python 3, because `input` behaves differently across versions. – Kevin Nov 03 '17 at 15:32
  • 3
    Welcome to SO. Please post the code you have. Visit the [help] and read [ask]. – 001 Nov 03 '17 at 15:32
  • Thank you Johnny. I’m unable to post the code, as I’m uncertain of how to indent the code. – Greg McCall Nov 03 '17 at 15:40
  • Come now, that isn't a good reason. Just Google "formatting stackoverflow question" – juanpa.arrivillaga Nov 03 '17 at 15:45
  • pi=3.14 radius=input("enter radius here") print("area="+str(pi*(radius**2))) – Greg McCall Nov 03 '17 at 15:53
  • You must convert the user input to a number. See this question for suggestions of how to handle invalid input. https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – Håken Lid Nov 03 '17 at 17:22

0 Answers0