Sections 12 & 13 Hacks
Problem 2
PROCEDURE heightenEmotions(myEmotion)
{ moreEnergy ← CONCAT(myEmotion, "!!!")
moreVolume ← UPPER(moreEnergy)
RETURN moreVolume }
heightenEmotions("im mad")
After that line, nothing will display. You are calling a part of a procedure that does not exist. Therefore, that part of procedure will show in a error or just nothing.
Problem 3
PROCEDURE calcFlightFootprint(numMiles, numPassengers) { CO2_PER_MILE ← 53.29
carbonPerFlight ← numMiles * CO2_PER_MILE
carbonPerPassenger ← carbonPerFlight / numPassengers
RETURN carbonPerPassenger
}
totalFootprint ← calcFlightFootprint(2451, 118) + calcFlightFootprint(3442, 252)
totalFootprint ← calcFlightFootprint((2451, 118) + (3442, 252))
1 and 3 are the only answers because these properly set up the ranges
c = 9
b = 9 * 9
a = b * c
print("the answer is", a)
What this function does is define c and b. Then it changes a based on the values of both c and b.
cost = 173
tax = .10
fullPrice = cost + (cost * tax)
print(fullPrice, "is the final cost after tax")
What I did here is define cost at what the given value was. Then I defined tax as .10 due to the fact that it is 10% of the costs value or .10 of it. Then i defined fullPrice as cost as well as adding the cost times tax to it to find the two values of cost and true tax. After, I have a simple print statement which displays our new variable
tempFar = 103
def convert():
global tempFar
tempFar = tempFar - 32
tempFar = tempFar * 5/9
print(tempFar, "is 103 Fahrenheit in Celsius")
convert()
Here I defined tempFar as the Fahrenheit given degrees. I then made a function called convert() which goes through converting the math of tempFar automatically. It globally calls on tempFar then puts it through some math. After it prints out along with the sentence
PROCEDURE updateStats(toprbyardspg, currentrbyards, totalGames)
{
topyardspg = 100
currentrbyards = 1260
totalGames = 12
currentrbyardspg = currentrbyards/totalGames
if currentrbyardspg > topyardspg:
topyardspg = currentrbyardspg
}
Whats happening here is first defining the variables. After, we have to introduce a new variable to get an accurate detail of topyardspg vs currentyardspg. Under the impression it does, the if statement activates and replaces the value.
PROCEDURE myList(canForwards)
{
i = 0
if i < 6
if canForwards:
moveForwards()
i += 1
else:
rotateRight()
moveForwards()
rotateLeft()
i += 1
moveForwards()
moveForwards()
rotateleft()
moveForwards()
moveForwards()
rotateRight()
moveForwards()
rotateLeft()
moveForwards()
moveForwards()
}
The procedure would be called "PROCEDURE myList"
This procedure runs though the loop 6 times as that was the only seeable pattern I could find. After that, I put it through a series of calls that would get it to the finish line
PROCEDURE beachRace(canForwards, atFinish):
finish = false
while finish = false:
if canForwards:
moveForwards()
else:
rotateLeft()
moveForwards
rotateRight()
if atFinish:
finish = true
break
I made a simple procedure that defines finish as false at first. What this does is the while loop will run infinitely until the conditions are met. Although, eventually they will.