Python Programming Beginner Level
Python Programming Beginner Level
if question == password:
print("Welcome to the hideout!")
else:
print("That's wrong! You can't enter.")
# Rollercoaster
age = input("How old are you?")
height = input("How tall are you? (4.3 for four foot three inches, etc.)")
rollAgain = "Y"
if rollAgain == "N":
print "See ya later!"
# Hangman
name = raw_input("What is your name? ")
word = "serendipity"
turns = len(word)
guesses = ''
playing = True
while playing:
failed = 0
for letter in word:
if letter in guesses:
print letter
else:
print "_"
failed += 1
if failed == 0:
print "\nYou won"
break
print
guess = raw_input("guess a character:")
guesses += guess
if guess not in word:
turns -= 1
print "Wrong\n"
print "You have", + turns, 'more guesses'
if turns == 0:
print "You Lose\n"
break
rollAgain = "Y"
if rollAgain == "N":
print "See ya later!"
# Hangman Advanced
word = "banana"
turns = len(word)
guesses = ''
playing = True
while playing:
failed = 0
for letter in word:
if letter in guesses:
print letter
else:
print "_"
failed += 1
if failed == 0:
print "\nYou won"
break
print
guess = raw_input("guess a character:")
guesses = guesses + guess
if guess not in word:
turns -= 1
print "Wrong!"
print "You have", + turns, 'more guesses'
if turns == 0:
print "You Lose\n"
break
myHealth = 100
monsterHealth = 100
while True:
print "Monster's health:",monsterHealth
print "My health:",myHealth
myAttack = random.randint(7,12)
myHeal = random.randint(5,15)
monsterAttack = random.randint(7,12)
monsterHeal = random.randint(5,15)
if monsterMove == 1:
print "MONSTER ATTACKS FOR",monsterAttack,"POINTS!"
myHealth = myHealth - monsterAttack
elif monsterMove == 2:
print "MONSTER HEALS FOR",monsterHeal,"POINTS!"
monsterHealth = monsterHealth + monsterHeal
if monsterHealth > 100:
monsterHealth = 100
if myMove == 1:
print "YOU ATTACK FOR",myAttack,"POINTS!"
monsterHealth = monsterHealth - myAttack
elif myMove == 2:
print "YOU HEAL YOURSELF FOR",myHeal,"POINTS!"
myHealth = myHealth + myHeal
if myHealth > 100:
myHealth = 100
#initializing board
board = []
for x in range(5):
board.append(["O"] * 5)
def print_board(board):
for row in board:
print row
print "Let's play Battleship!"
print_board(board)
def random_col(board):
return randint(0, 5)
ship_row = random_row(board)
ship_col = random_col(board)
turns = 4
#if the guess is wrong, mark the point with an X and start again
else:
print "You missed!"
board[guess_row][guess_col] = "X"
turns = turns - 1
adding = True
while adding:
ask = input("What do we need in our magic bag? Type 'Done' to exit. ")
if ask == 'Done':
print "Here's what's in your magic bag: ", bag
adding = False
else:
bag.append(ask)
# Draw a line
t = turtle.Turtle()
t.forward(50)
# Draw a square
"""
square = turtle.Turtle()
square.forward(50)
square.right(90) # Rotate clockwise by 90 degrees
square.forward(50)
square.right(90)
square.forward(50)
square.right(90)
square.forward(50)
square.right(90)
"""
"""
star = turtle.Turtle()
for i in range(50):
star.forward(50)
star.right(144)
"""
"""
painter = turtle.Turtle()
painter.pencolor("blue")
for i in range(50):
painter.forward(50)
painter.left(123) # Let's go counterclockwise this time
painter.pencolor("red")
for i in range(50):
painter.forward(100)
painter.left(123)
"""