generated from mwc/lab_names
In the greetings code, I added in the input line so when the code is ran, it asks the user for their name. I then assigned the input to a variable so it can print out the input at the end For the circle lab, i created a variable "pi" to assign the value of 3.14159265359 to it. I then created a variable to make a math sentence to compute the radius with the given radius. Checkpoint 1: A name is a varaible, and it refers to something. It is the label of the value. The value is the actual data that is stored in the name. -> name = value An everyday example of name and value would be in math where you can variables that represent certain values. For example, in the area formula of a triangle, the varaible b represents the name "base". The value of the is whatever the base of the triangle is. Variables can be useful in programming, rather than just using the value itself, because it will help keep your codes less repatiative. You could create a varaible and use the name of it in later lines with more ease. It overall would make the code less repatitve. Variables are also useful because you can change and reassign the value to the name. If at an earliar line you assign some value to a name, you can later alter that value by reassigning that name to carry out the rest of the program.
13 lines
235 B
Python
13 lines
235 B
Python
# circle_area.py
|
|
# --------------
|
|
# By MWC Contributors
|
|
|
|
print("This program will calculate the area of a circle.")
|
|
radius = float(input("What is the circle's radius? "))
|
|
pi = 3.14159265359
|
|
|
|
area = pi * (radius * radius)
|
|
|
|
print(area)
|
|
|