Python Forum
Understanding a piece of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding a piece of code
#2
Actually you are doing 10 * 3.14* 3.14 and the answer should be 98.596.

This is bad code. What does it do? area? area of what? By looking at the code I can see that this is the area of a circle with radius x, but I should not have to read the code. And why is y a variable? If this computes the area of a circle is y ever going to be something other than PI?
def circle_area(radius):
    """Returns area of circle with radius 'radius'"""
    return 3.14 * radius * radius
What is 3.14? It is kind of close to PI. If it is supposed to be PI, why not use PI?
import math

def circle_area(radius):
    """Returns area of circle with radius 'radius'"""
    return math.pi * radius**2
Reply


Messages In This Thread
Understanding a piece of code - by Michael1 - Jan-20-2022, 06:25 PM
RE: Understanding a piece of code - by deanhystad - Jan-20-2022, 06:34 PM
RE: Understanding a piece of code - by Michael1 - Jan-20-2022, 06:37 PM
RE: Understanding a piece of code - by deanhystad - Jan-20-2022, 07:11 PM
RE: Understanding a piece of code - by Michael1 - Jan-20-2022, 07:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 750 Sep-05-2023, 12:50 PM
Last Post: ToniE
  First piece of code Bearwulf 2 798 Aug-02-2023, 04:03 PM
Last Post: deanhystad
  Code understanding: Need help in understanding dictionary code jt123 0 493 Jul-09-2023, 01:13 PM
Last Post: jt123
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 1,826 May-09-2023, 08:47 AM
Last Post: buran
  How to make this piece concise leoahum 0 1,363 Sep-23-2021, 09:23 PM
Last Post: leoahum
  .maketrans() - a piece of code which needs some explanation InputOutput007 5 3,050 Jan-28-2021, 05:05 PM
Last Post: buran
  Beginner: I need help understanding few lines of a code. hop_090 1 1,723 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Extracting Rows From Data Frame and Understanding The Code JoeDainton123 0 1,463 Aug-03-2020, 04:08 PM
Last Post: JoeDainton123
  I am a newbie.Help me with this simple piece of code feynarun 3 2,867 Jan-08-2020, 12:40 PM
Last Post: perfringo
  How can I improve this piece of code? aquerci 3 2,242 Nov-17-2019, 10:57 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020