简体   繁体   中英

String to float conversion error in python code

I am getting the following conversion error and not sure where is the actual problem.

Exercise: Write a function that accepts two positive integers which are the height and width of a rectangle and returns a list that contains the area and perimeter of that rectangle.

def Area_of_a_Rectangle(width, height):
    '''Calculate the area'''
    Area = width * height

    # calculate the Perimeter'''
    Perimeter = 2 * (width + height)
    print("\n Area of a Rectangle is: ",Area)
    print(" Perimeter of Rectangle is: ",Perimeter)

width = float(input("Please Enter the Width of a Rectangle: "))  # This line errs out.
height = float(input("Please Enter the Height of a Rectangle: "))
Area_of_a_Rectangle(width, height)

**Error:**
Error in executing student function:
ValueError at line 11
could not convert string to float: 

The problem is with the entered value. If you enter a numeric value, line 11 should not give that error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM