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”

Leave a Reply