Tuesday, September 3, 2019

J1 Homework Solutions

Junior 1 Homework Solution:
Note:  Your task today was to place your source code in the compiler to identify your errors.  Hopefully you were able to apply correct syntax to test your algorithm.
Below are my solutions for the four assigned problems.  As mentioned in class, we will go over them in our next session after your testing in the compiler is attempted.  We will focus heavily on problem number 3 to learn about symbols used in algorithms.
Remember, there is no one solution for a problem, but syntax must be adhered to.

Problem #1:  The cost to go to Altun Ha are as follows:  $5.00 for Belizean and $10.00 for non-Belizeans.  Write an algorithm that calculates and shows the total for a group going to Altun Ha.

Solution:

'This algorithm is written by M. Young on September 3, 2019 for Junior 1'
belizean = 5.00
non_bze = 10.00
print "Enter the number of Belizeans in the group"
input num1
print "Enter the number of Non-Belizeans in the group"
input num2
total = (num1 * belizean) + (num2 * non_bze)
print "The total cost for the group is", total
input key


Problem #2: Write an algorithm that asks the user to enter the diameter of a circle.  The algorithm should calculate and show the circumference of a circle using the formula circumference = 2 Pi R

Solution:
'This algorithm is written by M. Young on 9/3/19 for Junior 1'
pi = 3.14
print "Enter the diameter of a circle"
input diameter
R = diameter/2
C = 2*pi*r
print "The circumference of the circle is", C
input key


Problem #3: Write an algorithm that prompts the user to enter the name and age of three friends.  The algorithm should find and show the average age of the friends.

Solution:
'This algorithm is written by M. Young on 9/3/19 for Junior 1'
print "enter the name and age of the first friend"
input nam1
input age1
print "enter the name and age of the second friend"
input nam2
input age2
print "enter the name and age of the third friend"
input nam3
input age3
avg = (age1 + age2 + age3) /3
print "The average age of the three friends is", avg
input key

Problem #4:  Write an algorithm that asks the user to enter a number and store in X.  The algorithm should find and show the square and cube of the number.

Solution:
'This algorithm is written by M. Young on 9/3/19 for Junior 1'
print "enter a number"
input X
sq = X * X
cu = X * X * X
print "The square of the number is", sq
print "The cube of the number is", cu
input key

No comments:

Post a Comment