[Python] Returning strings and floats in python functions

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    I need to make a function that returns a sentence with variables in it. But how do I exclude all the special string characters that I don't need? (e.g. ( or , or ')

    ef area_of_triangle( bottom, height ):
    area = 0.5 * bottom * height
    return 'The area of a triangle with a bottom of', bottom, 'and a height of', height, 'is', area, '.'


    this is my code for now but, the output always includes brackets, commas and apostrophes.

    So when i do: print(area_of_triangle(2, 1))

    the output is: ('The area of a triangle with a bottom of', 2.0, 'and a height of', 1.0, 'is', 1.0, '.')

    instead of: The area of a triangle with a bottom of 2.0 and a height of 1.0 is 1.0.

    How do i fix this?

    Continue reading...

Compartilhe esta Página