Skip to content

Instantly share code, notes, and snippets.

@colegleason
Created December 28, 2014 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colegleason/45e476d08fbccd14967b to your computer and use it in GitHub Desktop.
Save colegleason/45e476d08fbccd14967b to your computer and use it in GitHub Desktop.
Not my first program, but definitely early on in my programming career. Probably my Python script that wasn't a Project Euler problem. I remember writing this on a plane using a small netbook. Date: 2/11/10
#Rock Paper Scissors
import random
repeat = True
continue_game = True
while(repeat):
total_rounds = input("What is the maximum number of rounds that you wish to play? ")
curr_round = 1
wins = 0
losses = 0
draws = 0
continue_game = True
while(continue_game):
if wins == int(total_rounds/2) + 1:
print "Played " + str(curr_round - 1) + " rounds of " + str(total_rounds) + "."
print "Total Wins: " + str(wins)
print "Toatal Losses: " + str(losses)
print "Total Draws: " + str(draws)
print "You win!"
continue_game = False
elif losses == int(total_rounds/2) + 1:
print "Played " + str(curr_round - 1) + " rounds of " + str(total_rounds) + "."
print "Total Wins: " + str(wins)
print "Toatal Losses: " + str(losses)
print "Total Draws: " + str(draws)
print "You lose."
continue_game = False
elif curr_round > total_rounds:
if wins == losses:
print "Played " + str(curr_round - 1) + " rounds of " + str(total_rounds) + "."
print "Total Wins: " + str(wins)
print "Toatal Losses: " + str(losses)
print "Total Draws: " + str(draws)
print "It's a draw."
elif wins > losses:
print "Played " + str(curr_round - 1) + " rounds of " + str(total_rounds) + "."
print "Total Wins: " + str(wins)
print "Toatal Losses: " + str(losses)
print "Total Draws: " + str(draws)
print "You win!"
else:
print "Played " + str(curr_round - 1) + " rounds of " + str(total_rounds) + "."
print "Total Wins: " + str(wins)
print "Toatal Losses: " + str(losses)
print "Total Draws: " + str(draws)
print "You lose."
continue_game = False
else:
print "This is round " + str(curr_round) + " of " + str(total_rounds) + "."
user_choice = str(raw_input("Choose your weapon: \nr for rock \np for paper \ns for scissors:"))
possible_choices = ('r','p','s')
comp_choice = random.choice(possible_choices)
if user_choice == comp_choice:
print "Your choice: " + user_choice + " Computer's choice:" + comp_choice
print "It's a draw."
draws = draws + 1
elif user_choice == 'p' and comp_choice == 'r':
print "Your choice: " + user_choice + " Computer's choice:" + comp_choice
print "You win, for now."
wins = wins + 1
elif user_choice == 's' and comp_choice == 'p':
print "Your choice: " + user_choice + " Computer's choice:" + comp_choice
print "You win, for now."
wins = wins + 1
elif user_choice == 'r' and comp_choice == 's':
print "Your choice: " + user_choice + " Computer's choice:" + comp_choice
print "You win, for now."
wins = wins + 1
else:
print "Your choice: " + user_choice + " Computer's choice:" + comp_choice
print "You lose!"
losses = losses + 1
curr_round = curr_round + 1
continue_game = True
print "Game Complete"
def ask_yn(prompt, complaint='Yes or no, please!'):
while True:
ok = raw_input(prompt)
if ok in ('y', 'ye', 'yes'):
return True
elif ok in ('n', 'no', 'nop', 'nope'):
return False
else:
print complaint
repeat = ask_yn("Would you like to play again? [y/n]")
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment