All posts by jenk

Week 9 – 3/28/15

We will be well on our way to present our games at the STEM fest with this homework!  Please email Michael if you feel that you need help.
What I want you to get out of the assignment is that when you use glide you go from point A to pt B and you can’t effect the sprite as it glides. But if you use a loop and decrement the y position you can now put an if statement in the code. You already have all the code from the last class.

Please keep on working on your game for the STEM fest.

I have shared a project that you can use for the exercise. If you go to backdrops, you can find a background of an x-y axis. You might find this helpful.
1. Make an x and y axis on paper and plot the the following point (0,0), (1,1), (-3,-2), (5,-2)
Please use the shared link for the rest of the homework. The ball has two costumes: a blue and yellow costume.
2. In Scratch, make the ball  go to (100,100) using the blue costume.
3. Now make the  ball go from (100,100) to (100, -100)  using the glide command.
4. Now, what if we want the costume to change from blue to yellow  when  the y value is between 50 and -50.  If the ball is outside of 50 and -50, it should go back to blue. Can we do this using glide? Why not?
5.  Instead of using glide you can use a loop to move the ball. How do we have the costume change as specified in part 4?
Below is a representation of how the ball color should be changing based on its height.
Blue     —- change happens when y value is below 50
Blue   —- change happens again when y value drops below -50

Week 8 – 3/21/15

Next class we are going to be building structures in Minecraft. The code would look like something like this:
mc.setBlock(x, y, z, block_type)
So for example:
mc.setBlock(100, 200, 300, 3)
would mean to set a block at position:
z =300
block_type =3 —> dirt
I’d like you to write some code to print out numbers. In class I will show you how we can modify this code with very little extra code and build walls. It’s all about “for” loops.
Do a search on Google for “python for loop and nested for loops” if you want a refresher. There are tons of good videos. It’s a great habit to use Google to help you learn. I use it all the time.
A. write a program that will print out the following using a for loop:
B. Write a program that will print out the following using a nested for loop:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Week 6 – 3/7/2015

In class we went over how to write a function for our hangman game that will take a word as an input and then return a string with the correct number of underscores. For example
“banana”   —->  “_ _ _ _ _ _ _ _”
Now write a function that takes 3 inputs. First_Name, Middle_Name, and Last Name and returns a string which is the initials.
Lets call the function “Initials”
 Initials(“Michael”, “Zvi”, “Liebis”) —–> “MZL”
Some help:
if you have a string
x = “Michael”
x[0] is the first character or “M”
Test out this code:
def sum(x,y):
return x+y
s = sum(2,3)
print s

Week 6 – 3/7/2015

As we discussed in class, be prepared at the next class to make a proposal for the group project. I want you to at least have some graphics (no code) in place so you can explain how the “game” will work.
Write a program that asked the user for a password (That only you know and have put into the code). If they get it correct it prints out “Welcome” otherwise it prints out “You do not have Access”

Week 4 – Cat in the Hat

I made this for my daughter, Navah,  and thought some of my students might have some fun ideas as to how to make it better. If you modify the code I will show it to her.
I also need to make one for “AT” words. CAT, HAT, SAT etc. So feel free to make it and share. Thinking might be able to do a fun cat in the hat version.
Hope everyone is enjoying the break,

Week 4 – 1/31/15 – Hangman Part 1

Hang Man
We are going to code up the game Hangman  in Python. Once we do this we can then use Minecraft as a graphical interface for the game. This should be a lot of fun.

In order to do this we are going to be manipulating Strings. I am going to give you simple excercises that will help you code up the game. As always write a few lines of code and test.

A:   Lets assume that the mystery_word is “minecraft” so we will want to display  “ _ _ _ _ _ _ _ _”

Type in the following in IDLE

x= “minecraft”

What did this return?

y = “ab”
z = y + y

What did this return?

Now can you write a script where you set x equal to a word and we get the correct display?

For example:

x=“hello”  creates   “ _ _ _ _ _”

We might want to use this output again so how do you store it? What sort of variable do we use?

B:  Lets assume that the mystery_word is “chicken” and then the user is asked to guess a letter. Assume the user guesses “c”.  We then need to know that the the 1st and 4th letters have a c.

Python has many tools to help you with Strings. So there are many ways to do things and feel free to get creative.

Type in:

x= “minecraft”

What did this return?

Now type:

y = “hello”

What did this return?

Now type:

temp = y[0]
temp y[1]

Now write a script that takes a word and prints out a letter on each line so:

x = “summer”

prints out:


Now lets go back a bit:

y = “hello”
temp = y[0]

What printed out?

temp = y[1]
what printed out?
temp = y[2]

What printed out?

When we are repeating lines of code what is a good idea?

Now try to write a script that finds where a letter appears in a word (remember first position is 0)

So if:

x = “hello”
guess = “l”

we want to get 2,3.

Feel free to email me with questions or post them right here.

Week 3 – 1/24/15

There were 3 main things we worked on in the last class:
1. We spent some time using ” if .. then blocks”.  We say that if there were two cases we should use this structure as opposed to two “if blocks”. We also say that is there are 3 cases then we can put  an ” if .. then blocks” inside another ” if .. then blocks”.
2. When we get user input they are all going into the answer bucket. If we don’t move these inputs into other buckets they get overwritten and we loose the info. So if we are asking the user for 3 numbers and are going to do some computation with these 3 numbers we need to make sure we have 3 buckets.
3. We spent some time working on “and” and “or” blocks. We needed to use “or”  in our code for the guessing game as we excited the while loop when either the person had guessed correctly or they had used up all their tries.
Ask the user for 3 numbers. If all 3 numbers are equal have the sprite say “all equal.”
If 2 numbers are equal have the sprite say “2  are equal”. If none of the numbers are equal have the sprite say “none  are equal”. This assignment incorporates all 3 concepts we went over in class.
I like getting emails from students as it means they are working and learning. So feel free to email me for help on the assignment. Great job girls!!!!!

Week 3 – 1/24/15

There is an easy way to do this assignment. I am going to ask you to do it that way first. Then I want you to do it in a different way. It will become clear once we learn about functions why I want you to do it the second way too.
1. Ask the user for 5 numbers and have the program print out the largest number.
2. Ask the user for 5 numbers and and only after all 5 numbers are stored in memory do I want you to find the largest number. By stored in memory I mean that they are in buckets. You can use 5 variables or a list. Either way is good as we can then go over the advantage/disadvantage of each method.

Week 2 – 1/17/15

We talked a bit about variables in Python. We used the syntax:

"variable_name" = value

For example:

 x = 5

We talked about how you can think about this as there being a bucket that you place 5 in and then when you want to know what is in the bucket you use the variable x.

Now think about the snippet of code below run it in Python. Test it!!!

x = 5 
y = 7
y = x
print y

What prints out?

Now explain in words what is going on. Explain it with buckets if you’d like.

Now write a program in Python that asks the user for a number between 1-10. Then it asks the user for a second number between 1-10. Then prints out “Same” if the two numbers are the same and “Different” if they are different.

Now add a “for” loop to have the game played 3 times.

Then use a “while” loop to have the game played over and over again where the user is propted after each game to find out if he wants to play again or not.