Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rock-paper-scissor.py #769

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions rock-paper-scissor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from tkinter import *
import random

move = ["rock", "paper", "scissor"]

def fun():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fun has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.

computer = move[random.randint(0,2)]
player = var.get()
choose.config(text="Player choose " + player + " and computer choose " + computer)
if player==computer:
result.config(text="Its a Tie")

elif player=="rock":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

if computer=="paper":
result.config(text="Computer Win")

elif computer=="scissor":
result.config(text="Player Win")

elif player=="paper":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

if computer=="scissor":
result.config(text="Computer Win")

elif computer=="rock":
result.config(text="Player Win")

elif player=="scissor":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

if computer=="rock":
result.config(text="Computer Win")

elif computer=="paper":
result.config(text="Player Win")

root = Tk()
#root.geometry('250x300')

global result, var, choose

var=StringVar()

Rock = Radiobutton(root, text="Rock", variable=var, value="rock")
Rock.grid(row=0, column=0, padx=10, pady=10)
Rock.select()

Paper = Radiobutton(root, text="Paper", variable=var, value="paper")
Paper.grid(row=0, column=1, padx=10, pady=10)

Scissor = Radiobutton(root, text="Scissor", variable=var, value="scissor")
Scissor.grid(row=0, column=2, padx=10, pady=10)

submit = Button(root, text="submit", command=fun)
submit.grid(row=1, column=0, padx=10, pady=10, columnspan=3)

choose = Label(root, text="")
choose.grid(row=2, column=0, padx=10, pady=10, columnspan=3)

result = Label(root, text="")
result.grid(row=3, column=0, padx=10, pady=10, columnspan=3)

root.mainloop()