Writing Algorithms Flashcards

1
Q

The three parts to an algorithm:

A

Input
Process
Output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Input -

A

Here the user needs to input some data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Process

A

Here you’ll need to perform some form of process on your data e.g perform a calculation, perform a condition or check on your data)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Output

A

Output something to the user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Algorithm used to calculate the price of an item with a 10% off discount

A

price = input(“Please enter the process of the product: “) INPUT
new_price = price * 0.9 PROCESS
print(new_price) OUTPUT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write an algorithm that:
1. Allows the user to input the base and height of a triangle
2. Calculates the area of the triangle
3. Outputs the area of the triangle

A
  • height = input(“Enter the height: “)
  • base = input(“Enter the base: “)
  • area = (base * height) / 2
  • print(area)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A company wants to create a program that alerts the user to the freeing and boiling points
of water. The boiling point of water is 100 degrees Celsius, and the freezing point of water is 0 degrees Celsius.

Write an algorithm that:
• Allows the user to input the temperature of the water
• Calculates whether the water is boiling, freezing, or neither
• Outputs appropriate messages to the user

A

INPUT -
- water = input(“Input the temperature of the water: “)

PROCESS -
- if water > 100 then
- elseif water <= 0 then
- else
- endif

OUTPUT -
- print(“The water is at boiling point”)
- print(“The water is at freezing point”)
- print(“The water isn’t not boiling or freezing”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A parcel tracking company want to create a program to check whether an inputted parcel
number is the required 8 characters or not. If a parcel number is 8 characters it should output
the message ‘VALID’, otherwise it should output the message ‘INVALID’.

Write an algorithm that:
• Allows the user to input the parcel number
• Calculates whether the parcel number is 8 characters or not
• Outputs appropriate messages to the user

A

INPUT -
- parcel = input(“Enter the parcel number: “)

PROCESS -
- if parcel.length == 8 then
- else
- endif

OUTPUT -
- print(“VALID”)
- print(“INVALID”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A student wants to create a program using a function. The aim of the program is to return
the day of week based on its number e.g. Monday = 1, Tuesday = 2 etc. up to Sunday = 7.

Write an algorithm that:
• Creates a function named DayOfWeek and takes the number of the day as a parameter
• Calculates what day is outputted for each number
• Returns the day of the week

A

INPUT -
function DayOfWeek (number)
endfunction

PROCESS -
if number == 1 then
elseif number == then
(up to 7)
else
endif

OUTPUT -
day = “Monday”
day = “Tuesday”
(up to Sunday)
return day

How well did you know this?
1
Not at all
2
3
4
5
Perfectly