Search code examples
python-3.xinputpseudocodearea

Translating Pseudocode steps into Python algorithm


I'm entirely new to programming and I'm supposed to turn pseudocode into a Python algorithm for a class assignment. I've tested mine algorithm (if you can even call it that) a few too many times and keep coming up with error messages. Any suggestions or resources that might be able to help would be greatly appreciated!

Pseudocode Order:

  1. Declare Real radius
  2. Declare Real area
  3. Display “ Enter value for radius : “
  4. Input radius
  5. Set area = 3.14 * radius * radius
  6. Display Area

Attempted Code:

radius = 1.0 
Area = 1.0 
print(" Enter value for radius : ") 
radius = input(" Enter value for radius : ") 
Area = 3.14 * radius * radius 
print(Area) 

and the error:

TypeError: can't multiply sequence by non-int of type 'float'


Solution

  • Well, I will add some explain to this:

    radius = 1.0 #this is not mandatory, you can create the variable and assign the value in the same moment
    area = 1.0 
    radius = float(input(" Enter value for radius : ")) #here is so important to convert the input into a float, that's the other error you had
    area = 3.14 * radius * radius t isn't working
    print(area)