CS 1150 PEEE   Selection to Organize Actions


We have discussed the fundamentals of programming as consisting of data & actions (often on data) and organizing the actions via sequence, selection, repetition and modularization. This practice/learning activity will revisit those ideas in more detail focussing on selection to organize the actions in a program (or set of scripts). The learning activity is described after the Process Reminders below.

Process Reminders

Pair Programming

Keep the "pair programming" process in mind as you work. One person types and the other person watches and corrects, questions, etc. After a bit (at most 30 minutes) you change roles.


This activity is for you to learn, so it is not graded. The learning will be inferred in the PARR (Programming Activity and Reflection Report) document you (eventually) submit and in one of the in-term exams. Remember to add to your notes for the PARR.

If you have questions or difficulties

If you have questions about the assignment send me an e-mail or drop by my office. If you have a question while working on the assignment do the same. Keep in mind that when you encounter something you can't figure out you can/should think, explore, seek answers on google, etc. but, do not spend more than 15-30 minutes trying to overcome a particular error or problem.

Extra Credit

The syllabus noted a couple ways you might earn extra credit. I am adding another.

One is to share some aspect(s) of programming or Snap! you think others might not have experienced. You should annotate your program using the program notes (File icon | Program notes) and/or comments blocks (see p.68 of the Snap! Reference Manual. The annotation should describe or explain the learning/insight(s) you want to share.

To receive extra credit for such an annotated program on this activity you will also need to submit a copy of your algorithms. Either create a PDF of a document or include the text in your submission message.

The alternative method to work for extra credit is that the partnership could suggest additions to our how to do it page. You might suggest a revision to clarify (or finish) something that is there already or an entirely new topic. Please indicate how/why you think the would be helpful. Be sure you fully and clearly describe what you are talking about.

The third method to receive a bit of extra credit is to submit the "Create your own problems ..." that you created and solved. Include all three problems and a pseudo-code algorithm of each solution.

Submitting something for either kind of extra credit is as simple as sending an e-mail message. The message should:

Learning Activity

The goal here is to create and use Boolean expressions to decide which actions will get executed. We are at the point where programs/scripts are getting slightly more complex. We will be use selection statements (if and if...else... blocks. But when developing our algorithms and programs we will need to consider:

I suggest you use the following script in the Stage to control the program action.

Snap! repeat until 0 entered code

Then for each problem there will a matching script that gets executed by some sprite. The code for that would replace the "say" block in the following script and perhaps use a different number in the "when I receive __" block.

Snap! when I receive block

The Questions

  1. calculate pay (including overtime if need be)

    Get values from the user for hours and pay rate.

  2. report what the temperature is like

    Make up your own definitions for four conditions—frigid, cool, good, and hot. Get a value from the user for temperature.

  3. report what the weather is like

    Make up your own definitions for three conditions—bad, okay, and good. Include values for temperature, wind, and precipitation. Get values from the user for each condition.

  4. number is even?

    Determine whether the number entered by the user is even. An even number is divisible by 2 or equivalently an even number mod 2 will result in 0.

  5. characterize weight based on BMI

    BMI (body mass index) is often used to assess a person's weight. A BMI value of 18.5-25 is considered "normal" with 25-30 considered overweight and any value of 30 considered obese. Based on weight (in pounds) and height (in inches) values entered by the user characterize condition as underweight, normal, overweight, or obese. The formula for calculating the BMI is

               weight · 703
        bmi = --------------
  6. report height as below-normal, normal, above normal

    The normal range for height of American males is 69.5 inches ± 3 inches and for American females 64 ± 2.5 inches. Using whichever test you wish, get input from the user for height and characterize the height.

  7. report height as below-normal, normal, above normal (version 2)

    Using the information from the above item, get input from the user for height and gender, then characterize the height.

  8. report which quadrant the sprite is in
  9. report quadrant the user clicked in

    Snap! when block with and And block to perform code based on item number and the mouse down event

    Note: (I figured out a better way to do this I think.) You will probably want to use the similar to that at the right to accomplish this task. Your actions for this item would be placed beneath the hatted block shown.

  10. report mouse click position

    Add to the above script the possibility of the mouse being clicked on the x-axis, y-axis, or in one of the quadrants. Report whichever case it is.

  11. move depending on?

    Have one sprite determine whether it is closer to a second sprite than to the mouse (when the mouse is clicked) and if closer to the mouse glide there. Otherwise the sprite should move in a random direction the same distance as it is from the mouse.

  12. a little craps game

    Using two sprites with six dice costumes and a button you create for clicking to roll the dice, create a little craps game. Craps is played with two basic phases—come-out and point and starts in the come-out phase. Results are based on the roll total and the state of the game as described below.

    • In come-out phase

      There are three possible results of a roll in the come out phase.

      • winner — roll is 7 or 11

        announce "natural, winner"; state remains as initial state of the come-out phase

      • craps — roll is 2, 3 or 12

        announce "craps, loser"; state remains as initial state of the come-out phase

      • point established — roll is 4, 5, 6, 8, 9, or 10

        announce "point is __"; set the point value; state gets set to the point phase

    • In point phase

      There are three possible results of a roll in the point phase.

      • seven-out — roll is 7

        announce "seven out, loser"; set state to the initial state of the come-out phase

      • point — roll is the point value

        announce "point-value, winner"; set state to the initial state of the come-out phase

      • repeat — roll is anything besides 7 and the point value

        announce "same shooter"; state remains as initial state of the point phase

    Your script for the craps game will need to set the initial values for all variables (probably when it receives the action message). After that, the roll button sprite would use a (fairly complicated) if structure to evaluate the current state, roll the dice, and update the current state appropriately.

  13. create (and solve) your own problem(s) that require the use of selection statements