Last active
August 29, 2015 14:15
-
-
Save nrrb/4caf08174b229f38d5fd to your computer and use it in GitHub Desktop.
Beginner Projects (http://www.reddit.com/r/beginnerprojects)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.reddit.com/r/beginnerprojects/comments/19kxre/project_99_bottles_of_beer_on_the_wall_lyrics/ | |
# GOAL | |
# Create a program that prints out every line to the song "99 bottles of beer on the wall." This should be a pretty simple | |
# program, so to make it a bit harder, here are some rules to follow. | |
# RULES | |
# If you are going to use a list for all of the numbers, do not manually type them all in. Instead, use a built in function. | |
# Besides the phrase "take one down," you may not type in any numbers/names of numbers directly into your song lyrics. | |
# Remember, when you reach 1 bottle left, the word "bottles" becomes singular. | |
def amount_of_beer_in_words(bottles): | |
if bottles == 1: | |
noun = "bottle" | |
else: | |
noun = "bottles" | |
return "%d %s of beer" % (bottles, noun) | |
bottles_of_beer = 99 | |
while bottles_of_beer > 0: | |
print "{b} on the wall, {b}.".format(b=amount_of_beer_in_words(bottles_of_beer)), | |
bottles_of_beer = bottles_of_beer - 1 | |
print "Take one down, pass it around, {b} on the wall.".format(b=amount_of_beer_in_words(bottles_of_beer)) | |
print "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.reddit.com/r/beginnerprojects/comments/2ah82f/rock_paper_scissors/ | |
# You must make a rock paper scissors game | |
# Goal | |
# Ask the player if they pick rock paper or scissors | |
# Have the computer chose its move | |
# Compare the choices and decide who wins | |
# Print the results | |
# Subgoals | |
# Let the player play again | |
# Keep a record of the score e.g. (Player: 3 / Computer: 6) | |
import random | |
choices = ('rock', 'paper', 'scissors') | |
what_beats = {choices[i]: choices[(i+1)%len(choices)] for i in range(len(choices))} | |
score = {'computer': 0, 'player': 0} | |
while score['computer'] < 10 and score['player'] < 10: | |
while True: | |
player_choice = raw_input('rock, paper, or scissors? ') | |
if player_choice not in choices: | |
print "You didn't choose a valid option." | |
else: | |
break | |
computer_choice = random.choice(choices) | |
print "Computer chose %s." % computer_choice | |
if what_beats[player_choice] == computer_choice: | |
print "Computer wins, %s beats %s!" % (computer_choice, player_choice) | |
score['computer'] += 1 | |
elif what_beats[computer_choice] == player_choice: | |
print "Player wins, %s beats %s!" % (player_choice, computer_choice) | |
score['player'] += 1 | |
else: | |
print "No one won!" | |
print "Score is now Computer: %d, Player: %d" % (score['computer'], score['player']) | |
print "Game over! ", | |
if score['computer'] > score['player']: | |
print "Computer is the ultimate winner!" | |
elif score['player'] > score['computer']: | |
print "You are the ultimate winner!" | |
else: | |
print "A tie!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment