Assignment Series A4# Journeyman’s Piece

Part 1 – Map Pseudocode to Pythoncode
I’m not really familiar with a programming language yet, but I’ll try to go ahead with python!
Pseudocode:
constant input = [2, 4, 9, 1, 7]
variable result = 0
variable counter = 0
loop
exit if counter == input . length
result = result + input [ counter ]
counter ++
end loop
Pythoncode:
input = [2,4,9,1,7]
result = 0
counter = 0
while counter < len(input):
result = result + input[counter]
counter+ = 1
Pseudocode:
constant shapeCorners = { "Triangle": 3, "Rectangle": 4, "Pentagon": 5, "Hexagon": 6, "Heptagon": 7, "Octagon": 8 }
constant input = ["Triangle", "Hexagon", "Octagon"]
variable result = 0
variable counter = 0
loop
exit if counter == input . length
result = result + shapeCorners [ input [ counter ]]
counter ++
end loop
Pythoncode:
shapeCorners = {"Triangle": 3, "Rectangle": 4, "Pentagon": 5, "Hexagon": 6, "Heptagon": 7, "Oktagon": 8 }
input = ["Triangle", "Hexagon", "Ocatagon"]
result = 0
counter = 0
while counter != len(input):
result= result + shapeCorners[input[counter]]
counter = counter+1
Pseudocode:
method addShapeCorners = ( input ) => {
constant shapeCorners = { "Triangle": 3, "Rectangle": 4, "Pentagon": 5, "Hexagon": 6,
"Heptagon": 7, "Octagon": 8 }
variable result = 0
variable counter = 0
loop
exit if counter == input . length
result = result + shapeCorners [ input [ counter ]]
counter ++
end loop
return result
}
Pseudocode:
method calculateFactorialInteractive = () => {
print (" Please enter a number : ")
constant input = read ();
print (" The factorial of " + input + " is " + calculateFactorial ( read ()));
}
Pythoncode:
#Method
def calculateFactorial(input_factorial):
result_cf = 1
counter_cf = 1
while counter_cf <= input_factorial:
result_cf = result_cf * counter_cf
counter_cf = counter_cf+1
return result_cf
def calculateFactorialInteractive():
print("Please enter a number:")
input_number = input()
input_number = int(input_number)
print("The factorial of " , input_number, "is ", calculateFactorial(input_number))

