From 5e13684a234bf1916bc40bbd6a2b68c70a2d95b1 Mon Sep 17 00:00:00 2001 From: Louis Cooper Date: Sat, 15 Jul 2023 20:04:30 -0400 Subject: [PATCH] I created the python shapes files utilizign functions and loops. I modified the greeting program. Checkpoint1: A value is what something is and a name represents the value. For istance when we talk about pi, we just say the name pi, but the value is 3.14.. Variables are extremely useful in programming in order to minimize confusion, it helps to not use literals when possible. For instance if I am programming an arduino, I set a pin value so that if I change my circuit I dont need to rewrite that pin value all over my program, I instead use a variable to represent the pin value so I only need to change the variable line. Variables in code are useful and are reusable values that allow us to speed up programming, make code more readable and more efficient. Checkpoint2: A function is like a variable in several ways, you need to define the function (just like when you write a variable), functions are used to make repeatable, clean lines of code that reduce confusion. Functions actually allow for their own in-block temporary variables called "parameters", paired with arguments they give functions great flexibility and power. Functions are useful to do many different things in a program. For instance if I wanted to use several different area formulas, we might want to break them down into seperate functions. Or we can use functions inside of one another to make code cleaner and easier. --- circle_area.py | 6 ++++++ greetings.py | 4 ++-- shapes.py | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/circle_area.py b/circle_area.py index 513d6f7..7a93baf 100644 --- a/circle_area.py +++ b/circle_area.py @@ -1,6 +1,12 @@ # circle_area.py # -------------- # By MWC Contributors +import math #imports pi constant +##Refactor with a function## print("This program will calculate the area of a circle.") radius = float(input("What is the circle's radius? ")) +def circleArea(radius): + return math.pi * (radius ** 2) + +print(circleArea(radius)) \ No newline at end of file diff --git a/greetings.py b/greetings.py index 2d878a6..141e773 100644 --- a/greetings.py +++ b/greetings.py @@ -1,7 +1,7 @@ # greetings.py # ------------ -# By MWC contributors +# By Louis Cooper -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..bab03ce 100644 --- a/shapes.py +++ b/shapes.py @@ -1,11 +1,23 @@ # shapes.py # --------- -# By MWC contributors +# By Louis Cooper from turtle import * def triangle(side_length): - pass + for i in range(3): + forward(side_length) + right(120) + + + def rectangle(height, width): - pass + for i in range(2): + forward(width) + right(90) + forward(height) + right(90) + +#rectangle(200, 100) +#triangle(100) \ No newline at end of file