Rubberbandface
Rubberbandface

Reputation: 15

python 3 not working

Specifically I get a type error that says the pow() function does not take strings or integers?

I am following code character for integer from this site http://hetland.org/writing/instant-hacking.html.

The Area Calculator function is what I am copying down. The only difference is that I am enclosing the strings after the print statements with parenthesis as per Python syntactical structure. I am using Python version 3.4.3 and Linux Mint Ubuntu 16.04.1. I am running on a an old HP EliteBook with an CORE i5 vPro processor x86_64.

I have a number of images to help explain. The last image show that despite adding 1 as input the program prompts for the radius and that gives type error at the end. It does not matter what I put in input it skips the if statement and goes straight to prompting for radius. I realize there is a syntax error in the form of a the word calculator in the top comment. I fixed that.

Linux Version:

Python3 Version:

Area Calculator Code(mispelled word in comment)

Error in terminal:

Upvotes: 0

Views: 972

Answers (2)

Rubberbandface
Rubberbandface

Reputation: 15

The answer to my question was provided by simon. Here is the code `` # Area calculation program

print ("Welcome to the area calculation program")
print ("---------------------------------------")
print

# print out the menu:
print ("Please select a shape:")
print ("1 Rectangle")
print ("2 Circle")

# Get the user's choice:
shape = int(input("> "))

# Calculate the area:
if shape == 1:
    height = int(input("Please enter the height: "))
    width = int(input("Please enter the width: "))
    area = height*width
    print ("The area is ", area)
else:
    radius = int(input("Please enter the radius: "))
    area = 3.14*(radius**2)
    print ("The area is ", area)   

The answer was putting an int() function in front of the input functions so that the integer input would be recognized as such. The second issue was solved by placing the area variable to be printed out within the parenthesis. Thank you Simon!

Upvotes: 1

Xantium
Xantium

Reputation: 11603

Use radius = int(input("Please enter the radius: ")) because currently you are asking for an input which by default is a string. The int() function converts it to an integer.

See documentation for more details on this handy function.

Upvotes: 3

Related Questions