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.
Assignment:
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.

Week 2 – 1/17/15

We talked a bit about about using variables in Scratch.

We use the block: Set “variable_name” = value

For example set x = 5

We talked about how you can think about this as if there were 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 this and write the code in scratch. Test it!!!

set x = 5
set  y = x
say y

What prints out?
Now explain in words what is going on. Explain it with buckets etc….

Now write a program in Scratch 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.

Programming Minecraft With Raspberry Pi

Some of the girls expressed interest in programming the Minecraft world in Python. The best way to do this is on a Raspberry Pi. You can find some information on the process and hardware requirements here. While there are many options, the Kano Raspberry Pi kit comes in a simple package with everything we’ll need to get started. The kit is only $150 and can be purchased through their website. We will bring our Kano to the next class so you can check it out.

Week 1 – 1/10/15

Last class we  went over a bunch of control structures.

Note that “#” is used for comments in Python. The interpreter skips over the line. I will also be using # to start each script. Please run the following short scripts for a review:

# This is a script to demonstrate for loops
 for x in range(0,10):
....print(x)
# This is a script to demonstrate if statements
 x=10
 if x < 10:
....print("Yes")
 else:
 ....print("No")
# This is a script to demonstrate how to generate # a random integer
 from random import randint
 x= randint(0,5)
 print(x)
# This is a script to demonstrate how to get user # input
 x = input("Please input a number: ")
 print(x)
# This is a script to demonstrate how to put it  # all together. Note the "==" to test equality 
 from random import randint
 x= randint(0,5)
 guess = input("Please guess a number from 0-5:") 
 if (guess == x):
    print "You Win"
 else:
    print "You Lose"

This weeks assignment is to write a short python script. Have the computer select a random number between 1-20. Then have the played guess the number. If the player guesses corectly the computer prints out “You Win” otherwise it prints out “You Loose”

Week 1 – 1/10/15

This weeks assignment is to write out the instruction (pseudocode) that one would give a “simple” computer to play the following game.

1. Ask the player for her name

2. Tell the player she has 6 chances to guess a random number between 1-20.

3. Have the computer select a random number between 1-20

4.  Have the player guess a number. Let the computer respond with “You Win” , “too low” or “too hi”

5. After 6 guesses the computer responds with “You Loose”