From dda866676363147799ef76de314d1f842c3a7747 Mon Sep 17 00:00:00 2001 From: Pat Wick Date: Sun, 16 Jul 2023 20:35:32 -0400 Subject: [PATCH] CP1: imported math for pi, used the area formula A value is some object that exists, whereas a name is a reference to that value. An example where it is important to distinguish between a name and the value it represents is any reference to time. Sometimes generalization is acceptable ("I don't have time") but often the actual amount matters and so we care about the value, not the name itself. Variables are useful in programming because their values are able to be changed, by definition (variables can vary). This is useful because we can use variables to parameterize our code, allowing for easier modification and improvement or expansion. They can also make code more readable, even without documentation because effective naming of variables allows someone (even one who didn't write the specific code referenced) to see the variable names and hopefully understand what the values mean and how they are used in the program, for example, using "ballSpeed" vs "x". --- circle_area.py | 3 +++ greetings.py | 2 +- shapes.py | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/circle_area.py b/circle_area.py index 513d6f7..80cffef 100644 --- a/circle_area.py +++ b/circle_area.py @@ -1,6 +1,9 @@ # circle_area.py # -------------- # By MWC Contributors +import math print("This program will calculate the area of a circle.") radius = float(input("What is the circle's radius? ")) +area = math.pi * radius * radius +print(area) \ No newline at end of file diff --git a/greetings.py b/greetings.py index 2d878a6..f32240c 100644 --- a/greetings.py +++ b/greetings.py @@ -2,6 +2,6 @@ # ------------ # By MWC contributors -my_name ="Chris" +my_name = input('What is your name? ') greeting = "Hello, " + my_name print(greeting) diff --git a/shapes.py b/shapes.py index 731ec39..d6eadaf 100644 --- a/shapes.py +++ b/shapes.py @@ -5,7 +5,19 @@ from turtle import * def triangle(side_length): - pass + forward(side_length) + right(120) + forward(side_length) + right(120) + forward(side_length) + right(120) def rectangle(height, width): - pass + forward(width) + right(90) + forward(height) + right(90) + forward(width) + right(90) + forward(height) + right(90)