-1

Hey guys im still pretty new to Python and coding in general and am wondering why my code isnt working. I keep getting 2 errors. I am getting pretty frusterated, ive been at this for hours. Thanks

These are the error that I keep receiving. Typeerror: unsupported operand type for ** or pow(): 'str' and 'float' Typeerror: can't multiply sequence by non-int of type 'str'

I only list userChoice1 and 2 because thats where my problem lies atm.

1) Area (Square)
2) Area (Rectangle)
3) Area (Circle)
4) Perimeter (Square)
5) Perimeter (Rectangle)
6) Perimeter (Circle)
7) Exit Program
""")


usersChoice = input (" 1,2,3,4,5,6 OR 7? ")

while usersChoice!="7":

   if usersChoice == "1":
        print ("You have chosen area (Square)")
        length = input("input Length?")
        print ("Area is:") ,  length**2.0
   elif usersChoice == "2":
        print ("You have chosen area (Rectangle)")
        length = input("input length?")
        width = input("input width?")
        print ("Area is:") , length*width
Vinchenzo
  • 23
  • 2

2 Answers2

0

There are a couple of problems with your code. First, all input comes as strings; you have to convert ii to numbers. So, you'll want to write something like:

length = float(input("Input length?"))

Second, everything you want to print has to be in the argument to the print function. You'll need to change your print statements.

Once you fix those, you may want to add some error-handling in case the suer enters an invalid number.

Wtower
  • 18,848
  • 11
  • 103
  • 80
saulspatz
  • 5,011
  • 5
  • 36
  • 47
-1

You are presumably using python 3.x. Your problem is that input returns a string rather than what said string would represent if treated as a literal. You also need to put parenthesis around your arguments to print. It's no longer a keyword like yield or return, it's now just a regular builtin function. What you need is (note the float):

if usersChoice == "1":
     print ("You have chosen area (Square)")
     length = float(input("input Length?"))
     print ("Area is:",  length**2.0)
CrazyCasta
  • 26,917
  • 4
  • 45
  • 72