Way Back Wednesday

Today's Agenda

  • hax0r th3 c0n$0le
  • Finish Mad Libs Project
  • Counting with Snap!
  • Binary with Snap!
  • Pseudo code

Meeting link:

https://meet.lync.com/teals/davidburgess/FMWL7DR8


Letters to use for HEX


Cloning counter code with Tagijuan's Alien code and Hunter's Number base logic and My clone code:

http://snap.berkeley.edu/snapsource/snap.html#present:Username=mrburgess&ProjectName=Alien%20Count

Brain Warm Up - l33t hax0rs

Some of you have expressed how much more "impressive" Python looks than Snap!.

Before returning to your Madlibs project investigate these links:

Each "console" responds to you hitting any button on your keyboard. Have at it! Smack your keyboard and make it look like you have elite programming skills.

Once your brain and fingers feel warmed up continue with your Mad Libs project.

Go finish Mad Libs: https://repl.it/student/classrooms/40249

SNAP!?!?

For our next assignment we will be dusting off our old favorite tool Snap!

Recall the counting exercises from 9/20 and 8/30. (If you can't recall, click the links... computers are a wonderful tool for augmenting intelligence)

These counting assignments had us using a number sprite with 10 separate costumes to count and the other had us linking two sprites so that interaction with one caused the other to count upwards from whatever number it was on.

For this assignment you will need the number images from the 8/30 assignment.

Easy as 1-2-3

For our first assignment let's combine the steps from the previously mentioned assignments. If you have these assignments completed already feel free to reuse code to save time and effort.

Your code should have two sprites, one should be decorated with the provided numbers and the other should be a button of your very own design (reuse your beat machine button if you'd like).

When the button is pressed the number should increment by 1.

Submission requirements:

  • Your code has two sprites
    • one is a sprite with the values 0 through 9 as costumes
    • the other is a button sprite
  • The button sprite should change the costume of the number sprite every time it is clicked.
  • The number sprite should increment the number value it displays every time the button is pressed
  • Submit this assignment to the teals@mcpsweb.org address with a Subject line of <your name> - Count 1
  • In the email provide answers to the following questions:
    • What blocks did you use to complete this assignment?
    • What led you to use those blocks?
    • How many total costumes does your number sprite have?
    • How many different numbers can the number sprite represent as is?
    • What is the max number the sprite can represent?
    • What happens when you increment and the Sprite is on it's "last costume"?

It's over 9000!!!!!

Good! You can make Snap count!

But counting to just 9 is rather limiting. How can we make it so that by only pressing the increment button you can get to the maximum value of 99?

One sprite lets us get to 9. What is missing?

Introduce another number sprite that appropriately reacts to you incrementing past 9 and correctly displays two digit numbers.

The program should still behave like the first step where the only interaction is a clickable button that increases the right most number sprite by a single digit.

Submission requirements:

  • Your code has three sprites
    • two are sprites with the values 0 through 9 as costumes
    • the other is a button sprite
  • The button sprite should change the costume of the rightmost number sprite every time it is clicked. (Think adding 1 to 10 and the result being 11)
  • The rightmost number sprite should increment the number value it displays every time the button is pressed
  • The tens place sprite should increase every time the rightmost sprite increments from 9 back to 0
  • Submit this assignment to the teals@mcpsweb.org address with a Subject line of <your name> - Count 2
  • In the email provide answers to the following questions:
    • What additions did you make to your code to make it satisfy the new specifications above?
    • How would you make this code work a value up to 9999?

Base10 and friends

What you just did is base 10 counting! Hooooorrrrrrayyyyy!

You created a series of sprites that track different values of 10. The one's place and the ten's place. If you added more number sprites you introduced the hundreds place and thousands place and so on. Each time you introduced a new sprite you were able to add to a much higher number.

But what if the Number sprite did not have 0-9. What if we took our existing code that rolls over at 9 and changed it so it goes back to 0 sooner.

Try changing your code such that the Number sprites no longer go above the value 1. They should now only have 0 and 1. (Try changing your previous logic such that your code perceives 1 as the "last" number whereas previously it used 9 as your "last" number)

Whenever you increment the number sprite it should go to it's next costume just like it did before.

Whenever you try to increment past the last possible number the value should reset at 0 and the number sprite immediately to the left of the rolling over number should increment by one and so on.

When you finish with this you just made yourself a binary counter.

Submission requirements

  • Your code should have a series of number sprites
  • Your code should have an increment button
  • When the increment button is pressed the right most number sprite should go up by one
  • The number sprites should adjust accordingly to this update (incrementing past the "last number" should roll back to 0 and increase the number sprite to the left by 1)
  • Submit this assignment to the teals@mcpsweb.org address with a Subject line of <your name> - Count 3

Make the computer think so you don't have to

Now that you have a binary counter you can get the binary value for any number.

Change your button so it now instead prompts the user for a number. For whatever number the user put in repeat the previous increment code that many times. For instance the code could ask "Give me a number" and for an input of "2" the code would increment twice. In Binary mode this would leave you with two number sprites the first of which is 1 and the second of which is 0. If you were to do this on your second assignment that uses 0-9 then you would see the value 2 in the ones place.


For a bonus assignment try the following:

  • The number sprites should have the values 0-9. Ask the user which base they would like to count in. If they respond 10 the last value should be 9, if they respond 2 (binary) the last value possible should be 1, 8 the last value is 7, and so on.
  • Once you have the base value for counting ask the user for a number in Base10 (what we normally use, like 99 or 87) and then have your code increment the appropriate number of times to get the new representation of that value.
  • Bonus bonus, do all this with cloning

Planning your code

Look at the diagram below. This is someone mentally mapping whether they can afford to live alone. This is a flow diagram and is used to map thinking (just like actual code does). Review the style below and mimic it but instead use it to represent a routine in your life. Like checking whether it's raining or not and putting on the appropriate gear.

More info here: https://www.codeavengers.com/notes/planning/flowcharts

Pseudo Code

What you did just before this is a very helpful way to map your mental processes. Another method is to use what we call pseudo code:

For instance the above map could be represented as:

hourlypay = input "How much do you earn per hour?"

hoursperweek = input "How many hours a week do you work?"

weeklypay = hourlypay x hoursperweek

if weeklypay > 400 then

output can afford to live alone

else

output cannot afford to live alone

This is not actual code and will not run in your editor but it maps out what your code may look like. Pseudo code is nice because there are no rules, it needs to only make sense to you so that you can offload some of the thinking onto paper and prepare yourself for coding.

For the routine you mapped out create pseudo code that describes your graph

Once you finish making that pseudo code go back to our warm up and think about what that code is doing. How do you interact with the page and what is it doing based on that interaction?

Create pseudo code for the hacker project and once you feel comfortable investigate how you yourself would make code that does the same thing only using actual Python code.

Check out the string and print commands from the Python docs and if your feeling particularly up to the challenge try implementing the code for real: