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.

Leave a Reply