1 Replies - 1581 Views - Last Post: 04 November 2013 - 02:12 PM Rate Topic: -----

#1 flapsbro1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-October 13

Question about Simple Geometry calculator

Posted 04 November 2013 - 12:37 PM

So we were supposed to convert an old java program to python just to get introduced to it, I choose a simple calculator. Im getting errors that i dont know how to fix. And is does everything else look okay or am i missing something.


print ("This is a Geometry Calculator")
print ("1. To find the Area of a Circle")
print ("2. To find the Area of a Rectangle")
print ("3. To find the Area of a Triangle")
print ("4. Exit")
print ("")
pick = 0
pick = input("Enter the selection(1-4): ")

while pick != "4":

    if pick == "1":
        radius = input("Enter circles radius")
        area = 3.14 *(radius*2)
        print('Circles area is: ' , area)

    elif pick == "2":
        height = input("Enter Rectangles Height: ")
        length = input("Enter Rectangles Length: ")
        area = height * length
        print('Rectangle area is: ', area)

    elif pick == "3":
        height = input("Enter Triangle Height: ")
        base = input("Enter Triangle Base: ")
        area = (height * base) * 0.5
        print ('Triangles area is: ', area)

    else:
        print("Calculator has stopped.")
        break


if the user inputs 1 and puts the radius
line 24, in <module>
area = 3.14 *(radius*2)
TypeError: can't multiply sequence by non-int of type 'float'

if the user inputs 2 and puts the height and length it gives this error
line 30, in <module>
area = height * length
TypeError: can't multiply sequence by non-int of type 'str'

if the user inputs 3 and puts the height and base it gives this error
line 36, in <module>
area = (height * base) * 0.5
TypeError: can't multiply sequence by non-int of type 'str'

ive tried this but it doesnt work
 radius = double(input("Enter circles Radius: "))



Is This A Good Question/Topic? 0
  • +

Replies To: Question about Simple Geometry calculator

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Question about Simple Geometry calculator

Posted 04 November 2013 - 02:12 PM

radius = double(input("Enter circles Radius: "))

input() returns a string so you are along the right lines. There is no double in Python:

radius = float(input("Enter circles Radius: "))

FYI "hello" * 4 would return hellohellohellohello which is why you are seeing the specific error messages about a sequence.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1