generated from mwc/lab_names
I created functions and did math using python
checkpoint 1 -A name is like an identifier that is empty. It only gains importance once it is assigned a value, which is the data stored under the name. It's like the net worths. people are just people until you find out their networth. -it's easier to refer back to and connect your code when using variables. It also allows you to change the values without having to change all your code checkpoint 2 -a function is similar to a variable because it makes it easier to reference a set of code. With it, you don't need to repeatedly write out the same few lines of code -functions are like mini projects in a big scheme. You can solely achieve the big picture by completing functions. The best part of is that you can check if a function is working wihout having to run all your code. the names lab is a good example, I tested the shapes as I wrote the functions and once they were done, I could run the drawing.
This commit is contained in:
@@ -4,3 +4,8 @@
|
|||||||
|
|
||||||
print("This program will calculate the area of a circle.")
|
print("This program will calculate the area of a circle.")
|
||||||
radius = float(input("What is the circle's radius? "))
|
radius = float(input("What is the circle's radius? "))
|
||||||
|
import math
|
||||||
|
|
||||||
|
area= math.pi*radius**2
|
||||||
|
print("area is "+ str(area))
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
# ------------
|
# ------------
|
||||||
# By MWC contributors
|
# By MWC contributors
|
||||||
|
|
||||||
my_name ="Chris"
|
my_name ="Ilma"
|
||||||
greeting = "Hello, " + my_name
|
greeting = "Hello, " + my_name
|
||||||
print(greeting)
|
print(greeting)
|
||||||
|
|||||||
20
shapes.py
20
shapes.py
@@ -5,7 +5,23 @@
|
|||||||
from turtle import *
|
from turtle import *
|
||||||
|
|
||||||
def triangle(side_length):
|
def triangle(side_length):
|
||||||
pass
|
pendown()
|
||||||
|
right(90)
|
||||||
|
for x in range(3):
|
||||||
|
forward(side_length)
|
||||||
|
right(120)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rectangle(height, width):
|
def rectangle(height, width):
|
||||||
pass
|
pendown()
|
||||||
|
right(90)
|
||||||
|
for x in range(2):
|
||||||
|
forward(height)
|
||||||
|
right(90)
|
||||||
|
forward(width)
|
||||||
|
right(90)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user