An algorithm a day Ye a r 1 0 D i g i t a l Te c h n o l o g i e s Bream Bay College What is an algorithm? An algorithm is a step-by-step procedure that allows a computer to solve a problem. Contents 1. Comparing Numbers (Scratch Solution) 2. Days of the Week (Scratch Solution) 3. Roll the dice! (Scratch Solution) 4. Teach an old dog new tricks… (Scratch Solution) 5. Adding up a list (Scratch Solution) 6.Taxi! Taxi! (Scratch Solution) [Test Data] 7. Bear with me (Scratch Solution) [Test Data] 8. Isosceles (Scratch Solution) [Test Data] 9. 10. 1. Comparing Numbers 5 is bigger than 3 Write an algorithm which: a. Asks the user to input two numbers. b. Outputs the larger of the two numbers along with a suitable message. Contents 1. Comparing Numbers—Scratch Contents 2. Days of the Week If Monday = 1, Tuesday = 2 etc, write an algorithm which: a. Asks the user to enter a number. b. Outputs the day that the number represents. c. Validates the number so that an error message displays if the number is not a valid weekday number. d. Makes the program loop. Contents 2. Days of the Week—Scratch Contents 3. Roll the dice! A program has been written to obtain three random virtual dice rolls. a. Rewrite this program so that it uses a loop. b.Create your own dice sprite in Scratch, with six costumes. Change the costume to match each dice Contents roll. 3. Roll the dice!—Scratch Pa r t a Pa r t b • This needs about three blocks. • A solution will be posted in due course. Contents 4. Teach an old dog new tricks… A dog that is 5 years old is equivalent to a 42 year old human. Write a program that converts the age of a dog to the equivalent age of a human. a. Ask for the age of the dog in years. b. If the age is 2 or less, the human equivalent is 12 times the age. c. If the age is more than 2, the human equivalent is 24 for the first 2 years, plus 6 for Contents every additional year. 4. Teach an old dog…—Scratch Contents 5. Adding up a list a. In Scratch, make a list called numbers. b. Add each of the following to your numbers list: 2, 5, 3, 6, 2, 3, 6, 4. c. Write a program which adds up the numbers in the list and displays the result. Use a loop for doing this. d. Calculate the average (mean) number. Contents 5. Adding up a list—Scratch Explain the purpose of each block in this program. Contents 6. Taxi! Taxi! A taxi firm charges $5 for the first kilometre and $2 for every km after that. If there are 5 or more passengers, an extra 50% is added to the price. Create an app in Scratch which: a. Asks for the number of passengers (1 to 12); b.Asks for the distance (1km to 60km); c. Calculates the price of the journey; d.Outputs the price on the screen. Contents 6. Taxi! Taxi!—Test Data Number of passengers Distance (km) Cost 1 5 $13 4 12 $27 5 15 $49.50 12 8 $28.50 14 14 Invalid Number 3 65 Invalid Distance Contents 6. Taxi! Taxi!—Scratch Contents 7. Bear with me In a factory, the wage earned by a worker is either $5 for every teddy bear they have made or $20 for every hour they have worked, whichever is higher. Make a Scratch app which: a. Asks for the number of teddy bears made (1 to 1,000) and the number of hours worked (1 to 50); b. Calculates the wages for the number of teddy bears made; c. Calculates the wages for the number of hours worked; d. Outputs the larger of the two results. Contents 7. Bear with me—Test Data Teddy Bears Hours Per Teddy Per Hour Output 28 6 $140 $120 $140 52 15 $260 $300 $300 200 40 $1,000 $800 $1,000 72 22 $360 $440 $440 1001 50 Invalid Teddies 800 51 Invalid Hours Contents 7. Bear with me—Scratch Contents 8. Isosceles An isosceles triangle is one which has at least two equal length sides. Create a Scratch program which: a. Asks the user to enter the lengths of a triangle; b.Works out if the triangle is isosceles; c. Outputs a message stating whether the triangle is isosceles or not. Contents 8. Isosceles—Test Data Side 1 Side 2 Side 3 Output 3 4 5 Not Isosceles 7 7 4 Isosceles 12 5 12 Isosceles 14 8 8 Isosceles 5 12 13 Not isosceles 9 9 9 Isosceles Contents 8. Isosceles—Scratch Contents
© Copyright 2025 Paperzz