-
-
Notifications
You must be signed in to change notification settings - Fork 543
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(): | ||
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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
There was a problem hiding this comment.
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.