DEV Community

Anonmike
Anonmike

Posted on

Rock,paper,scissors With python

Ok guys this is my first post here on Dev and today am gonna be talking on making rock paper scissors using Python
So let's get started

Requirements:
Python IDLE
Tkinter module (inbuilt moudle)
Radom module (inbuilt Python module)

As we all see all the module needed for this programme are all inbuilt Python module I.e the don't need to be downloaded

Follow me on Instagram @anon_mike1
https://www.instagram.com/invites/contact/?i=ipimgm36ir5v

import tkinter
import random

stats = []

def get_winner(call):
if random.random() <= (1 / 3):
choose = "rock"
elif (1 / 3) < random.random() <= (2 / 3):
choose = "scissors"
else:
choose = "paper"

if (choose == "rock" and call == "paper") or (choose == "paper" and call == "scissors") \
        or (choose == "scissors" and call == "rock"):
    stats.append('W')
    result = "You won"
elif choose == call:
    stats.append('D')
    result = "It's a tie"
else:
    stats.append('L')
    result = "You lost"

global output
output.config(text="Computer choosed: " + choose + "\n" + result)
Enter fullscreen mode Exit fullscreen mode

def pass_s():
get_winner("scissors")

def pass_r():
get_winner("rock")

def pass_p():
get_winner("paper")

window = tkinter.Tk()

scissors = tkinter.Button(window, text="Scissors", bg="red", padx=10, pady=5, command=pass_s, width=15)
rock = tkinter.Button(window, text="Rock", bg="grey", padx=10, pady=5, command=pass_r, width=15)
paper = tkinter.Button(window, text="Paper", bg="white", padx=10, pady=5, command=pass_p, width=20)
output = tkinter.Label(window, width=30, fg="red", text="What's your call?")

scissors.pack(side="left")
rock.pack(side="left")
paper.pack(side="left")
output.pack(side="right")
window.mainloop()

for i in stats: print(i, end=" ")
if stats.count('L') > stats.count('W'):
result = "\nYou loose"
elif stats.count('L') == stats.count('W'):
result = "\n its a draw."
else:
result = "\nYou win"

print(result)

Happy programming ❤❤

Top comments (0)