Created
September 24, 2014 16:12
-
-
Save tibbon/da6a27a1d42131799296 to your computer and use it in GitHub Desktop.
WDI Method and Scope Exercises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### | |
# Exercise 1 | |
# What bug prevents the circle circumference from being calculated in the code section below? | |
# How can you prevent such a bug in the future? | |
#### | |
def circumference(r) | |
return 2 * pi * r | |
end | |
radius = 2 | |
c = circumference(radius) | |
#### | |
# Exercise 2 | |
# What is the value of 'a' at the comment below? | |
# Why? | |
#### | |
def area(r) | |
pi = 3.14597 | |
a = 2 * pi * r | |
return a | |
end | |
cir_area = area(3) | |
# What is the value of 'a' here? | |
#### | |
# Exercise 3 | |
# What is the value of 'radius' at the comment below? Why? | |
# What is the value of 'pi' at the comment below? Why? | |
# What will be printed to screen from the code below? | |
#### | |
def summed_surface_area_of_two_spheres(sphere_radius_1, sphere_radius_2) | |
result = surface_of_sphere(sphere_radius_1) + surface_of_sphere(sphere_radius_2) | |
# What is the value of 'radius' at this point? | |
# What is the value of 'pi' at this point? | |
return result | |
end | |
def surface_of_sphere(radius) | |
pi = 3.14159 | |
answer = pi * 4 * Math.sqrt(radius) | |
pi = 0 | |
return answer | |
end | |
summed_surface_area_of_two_spheres(10, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment