Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- from tkinter import *
- """******
- Task 3
- ******"""
- """*************************************
- Part 1 changes:
- Fixed errors
- allowed acceptance of lower case letters
- *************************************"""
- ###create a list of play options
- ##t = ["rock", "paper", "scissors"]
- ##
- ###assign a random play to the computer
- ##computer = t[randint(0,2)]
- ##
- ###set player to Falsea
- ##player = False
- ##
- ##while player == False:
- ###set player to True
- ## player = input("Rock, Paper, Scissors?").lower()
- ## if player == computer:
- ## print("Tie!")
- ## elif player == "rock":
- ## print("You win!", player, "smashes", computer)
- ## elif player == "paper":
- ## if computer == "scissors":
- ## print("You lose!", computer, "cut", player)
- ## else:
- ## print("You win!", player, "covers", computer)
- ## elif player == "scissors":
- ## if computer == "rock":
- ## print("You lose...", computer, "smashes", player)
- ## else:
- ## print("You win!", player, "cut", computer)
- ## else:
- ## print("That's not a valid play. Check your spelling!")
- ## #player was set to True, but we want it to be False so the loop continues
- ## player = False
- ## computer = t[randint(0,2)]
- """
- Part 2 additions :
- Added equation based decisions
- Added Spock , Lizard and magical eLF
- Added GUI
- """
- def check(player , computer):
- if selection[player] == computer:
- print("Tie")
- elif computer == selection[(player-1)%6] or computer == selection[(player+2)%6]:
- print("You win!",selection[player],"beats",computer)
- else:
- print("You lose!",computer,"beats",selection[player])
- def main(player):
- value = selection.index(player)
- computer = selection[randint(0,5)]
- check(value , computer)
- def GUI():
- window = Tk()
- window.title("Rock , paper , sissors , spock , lizard , eLF")
- label = Label(window,text="Click on Rock , paper , Scissors , Spock , Lizard or magical eLF")
- label.pack()
- topframe = Frame(window)
- topframe.pack(side=TOP)
- rock = Button(window, text="Rock", fg="red",command= lambda: main("rock"))
- paper = Button(window, text="paper", fg="blue",command= lambda: main("paper"))
- scissor = Button(window, text="scissor", fg="green",command= lambda: main("scissors"))
- spock = Button(window, text="Spock", fg="purple",command= lambda: main("spock"))
- lizard =Button(window, text="lizard", fg="yellow",command= lambda: main("lizard"))
- eLF = Button(window, text="eLF", fg="aqua",command= lambda: main("eLF"))
- rock.pack(side=TOP)
- paper.pack(side=TOP)
- scissor.pack(side=TOP)
- spock.pack(side=TOP)
- lizard.pack(side=TOP)
- eLF.pack(side=TOP)
- window.mainloop()
- #Globals
- selection = ["rock","paper","scissors","spock","lizard","eLF"]
- GUI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement