University Computer Based Activities Assessment 1 - Python Solutions

Verified

Added on  2022/08/12

|7
|942
|37
Homework Assignment
AI Summary
This document presents a comprehensive solution to the Computer Based Activities Assessment 1, covering various programming concepts and problem-solving techniques. The solution begins by identifying and explaining the four basic flowchart symbols and their representations. It then analyzes a flowchart depicting the Euclidean algorithm, discussing its goal and potential failure conditions. The document further includes algorithms demonstrating sequence, conditional logic, and iterative processes, followed by their corresponding Python code implementations. The solution also involves writing a Python program with user input, calculations, and conditional branching, along with a discussion on potential logical errors and their corrections in a given code snippet. The assessment tasks cover flowcharts, algorithms, and Python programming including practical code examples with explanations, making it a valuable resource for students studying computer science.
Document Page
Running head: COMPUTER BASED ACTIVITIES
Computer Based Activities
Student Name:
Student ID:
University Name:
Paper Code:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2Computer Based Activities
Task 1:
The four basic flowchart symbols are-
Oval
Rectangle
Arrow
Diamond
Oval- The oval symbol represent the beginning or end of any process.
Rectangle- The rectangle symbol represent the go-to-symbol once the flowcharting has been
started. It represent the step by step implementation of the flowchart diagram.
Arrow- The arrow symbol represent the correct direction after each process. Also arrows are of
different types. Arrows are also used to emphasize certain steps in your process.
Diamond- The diamond symbol represents any condition or decision making statements to move
forward.
Task 2:
1)
The flowchart indicates the Euclidean algorithm, were these types of method or algorithm
are generally used for computing the GCD or we can say the greatest common divisor of the two
positive whole number. Sometimes it is also called the highest common factor or the HCF in
short. Basically, GCD of the two positive whole number is the largest number which divides
both the numbers without leaving any remainder.
2)
As from the flowchart it can be seen that two oval symbol with same process has been
place thus the process will not stop under any circumstances. The logic of the flowchart is
correct but the flowchart symbols are not appropriate due to which the process will never ends.
Document Page
3Computer Based Activities
Task 3:
1. Start.
2. Declare variable usage.
3. Read usage.
4. Multiply usage with 2.4
usage = usage*2.4
5. Display usage
6. Stop
Task 4:
1. Start
2. Declare variable usage, Cost.
3. Read usage.
4. Multiply usage with 2.4
usage = usage*2.4
5. If usage < 10.0
Cost = usage * 2.0
Else if usage > =10.1 and usage <=20.0
Cost = usage * 1.8
Else
Cost = usage * 1.5
6. Display Cost
7. Stop
Document Page
4Computer Based Activities
Task 5:
1. Start
2. Declare variable num, sum=0, i=0
3. Read num
4. While i<=num
sum = sum + i
i=i+1
5. Display sum
6. Stop
Task 6:
1. Start
2. Declare hour, rate, gp, tax, net, choice
3. Read hour, rate.
4. gp = hour * rate (Gross pay)
5. tax = gp * 0.1
6. net = gp - tax
7. Display gross pay is gp
Display tax deducted is tax
Display net pay is net
8. Read choice
9. If choice == “y” or choice == “Y”
Goto step 3
Else
Display ending the program
10. Stop
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
5Computer Based Activities
Task 7:
Let hour=8, rate=100
Then,
Gross pay = 800
Tax = 800*0.1 = 80
Net pay = 800-80 = 720
Again, with different inputs if the operator wants to process another pay.
Let hour=5, rate=150
Then,
Gross pay = 750
Tax = 750*0.1 = 75
Net pay = 750-75 = 675
The algorithm meets the program specifications correctly.
Task 8:
Python Program
while True: #condition for continuation.
hour=int(input("Enter the total hour of work: ")) #input the value of hour.
rate=int(input("Enter the rate: ")) #input the value of rate.
gp=hour*rate #Calculating the Gross Pay.
tax=gp*0.1 #Calculation tax payble from the Gross pay.
net=gp-tax #Calculating the net pay after tax deduction.
print(f"The Gross pay is {gp}\nTax deducted will be {tax}\nThe net pay will be {net}")
Document Page
6Computer Based Activities
choice=input("Want to process another pay(y/n): ") #input for operator if the operator want to
process another pay or not.
if choice == "y" or choice == "Y": #condition to proceed depending upon operator choice.
continue
else:
break
Task 9:
Please follow the read-me.txt file for the appropriate answer of this particular question
Task 10:
The first logical error was that while printing the original temperature for both the
temperature it was written Celsius, now it has been fixed and the next logical error was the
formula to convert Fahrenheit to Celsius which has now been corrected with brackets as bracket
have higher preference than any other operator. The below is the corrected code shown.
convertString = 'It was converted to '
CelsiusString = 'Celsius'
fahrenheitString = 'Fahrenheit'
gotConvertTo = 0
#while get letter c or f from the user and set up output string
while gotConvertTo == 0:
convertTo = input('Convert to c or f?: ')
if convertTo == 'c':
gotConvertTo = 1
Document Page
7Computer Based Activities
convertString = CelsiusString
elif convertTo == 'f':
gotConvertTo = 1
convertString = fahrenheitString
else:
print('Type in c for Celsius or f for Fahrenheit')
# Prompt user for temperature, convert the temperature and
# display results.
temp = int(input('Type in the temperature to convert: '))
if convertTo == 'c':
newTemp = (temp - 32) * 5/9
print ('Original temperature entered was',temp, 'Fahrenheit')
else:
newTemp = 32 + temp/5 * 9
print ('Original temperature entered was',temp, 'Celsius')
print (convertString, round(newTemp,2))
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]