• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

View

# Scratch Exercises - IF-ELSE Statements

last edited by 1 year, 8 months ago

Part A: Simple Selection Exercises

1. Create a program where the user can enter a grade (as a percent), and the program will tell the user if they pass or fail the course.  A mark of 50 or above is a pass, while a mark below 50 is a fail.  To do this program, you will need:
3. compare the grade to the number 50 using two if controls, or a single if-else control
4. tell the user if they pass or fail

2. Create a program that asks the user their first name.  Depending upon the answer, your program has two possible responses:  "I don't know you", or "Hey, we have the same first name".

3. Create a program that asks the user for two numbers and then determines which number is larger.

4. Create a program which asks the user a simple math question (for example, what is 3 + 5?).  Let the user enter their answer and compare their answer to the correct answer.  If the user gets it right, congratulate them.  If they get it wrong, tell them what the correct answer was.
extension: Make this program more interesting by using the random number generator to create a new question each time.

5. Create a program where the user enters their 4 grades (numbers) for the semester.  The program calculates the average grade and then tells the user if they made the honour roll (80% or higher average).
1. Extend this program so that it also tells the user how many credits they achieved this semester (hint: count up the number of credits as the user enters each grade).  Remember that a student only gets a credit if they passed the course.

Part B: More Advanced Selection Exercises

1. Create a program where the user can enter a grade (as a percent), and the program will respond with the associated level (over 90 is 4+, over 80 is 4, over 70 is 3, over 60 is 2, over 50 is 1, below 50 is R).
[hint1] [hint2] [hint3]

2. Create a program that asks the user for three numbers, and determines the (a) smallest number; (b) largest number; and (c) middle number.  Don't try to do all three parts at once.  (a) and (b) are the same difficulty, but (c) is much harder.

3. Create a program that simulates tossing a coin (a random number between 1 and 2, where 1 is heads and 2 is tails).  Let the user guess, "heads" or "tails", and tell them if they got it right.
(Hint: There is a random number generator under the 'Operators' menu)

4. Write a program that plays one round of rock, paper, scissors.  Rock beats scissors.  Paper beats rock.  Scissors beats paper.
1. Extend: Assume two players, and each player will enter their selection either as words ("rock", "paper", "scissors") or using a menu (1 = rock, 2 = paper, etc).
2. Extend: Make the game more interesting by having the computer play against the human.  Use random numbers for the computer's choice (1, 2, or 3) and compare against the user's choice.
3. Extend: Explore more of the interface in Scratch by letting the user make their choice by choosing between images of rock, paper, and scissors, and clicking on the one they want.  You could also show the result of the match graphically (but you should also SAY the result).

5. Create a program which asks the user for an integer number and determines if the number if even or odd.
Hint 1: Even numbers are divisible by 2, with no remainder.
Hint 2: You may wish to research the mathematical operator called "modulo", which can be very useful for this application.