teratail header banner
teratail header banner
質問するログイン新規登録
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

662閲覧

python じゃんけん You win!のところを正確に出したいです。(draw!,you lose!もだせるようにしたい)

suzu

総合スコア3

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/01/26 14:57

編集2022/01/26 14:58

0

0

イメージ説明

import tkinter as tk import random def hand(rpc): if(rpc==0): return "Rock" if(rpc==1): return "Paper" if(rpc==2): return "Scissors" def checkwinner(chand,yhand): if yhand==chand: print("Draw!") result=tk.Label(window,text="Draw!",width=10) else: if(yhand==0) and (chand==2): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==0) and (chand==1): print("You lose!") result=tk.Label(window,text="You lose!",width=10) if(yhand==1) and (chand==0): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==1) and (chand==2): print("You lose!") result=tk.Label(window,text="You lose!",width=10) if(yhand==2) and (chand==1): print("You win!") result=tk.Label(window,text="You win!",width=10) else: if(yhand==2) and (chand==0): print("You lose!") result=tk.Label(window,text="You lose!",width=10) return result import random comphand=random.randint(0,2) def rock(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,0) def paper(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,1) def scissors(): comphand=random.randint(0,2) result=tk.Label(window,text="You win!",width=10) result=tk.Label(window,text="Draw!",width=10) result=tk.Label(window,text="You lose!",width=10) checkwinner(comphand,2) import tkinter as tk window=tk.Tk() window.geometry("640x300") window.title("Rock-Paper-Scissors Game") window.configure(bg="#FFFFFF") canvas=tk.Canvas(window,bg="#FFFFFF",width=640,height=220) canvas.place(x=0,y=0) rockImage=tk.PhotoImage(file="rock.gif") paperImage=tk.PhotoImage(file="paper.gif") scissorsImage=tk.PhotoImage(file="scissors.gif") canvas.create_image(10,30,image=rockImage,anchor="nw") canvas.create_image(210,30,image=paperImage,anchor="nw") canvas.create_image(410,30,image=scissorsImage,anchor="nw") rockbutton=tk.Button(window,text="Rock",width=6,command=rock) paperbutton=tk.Button(window,text="Paper",width=6,command=paper) scissorsbutton=tk.Button(window,text="Scissors",width=6,command=scissors) rockbutton.place(x=80,y=230) paperbutton.place(x=280,y=230) scissorsbutton.place(x=480,y=230) result=tk.Label(window,text="You win!",width=10) result.place(x=270,y=270)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yuina8686

2022/01/26 23:59

やりたいことが丸投げの質問はあまりよくありません。 何ができないのか、どのようなエラーなのか、記載してほしいです。
guest

回答1

0

ベストアンサー

https://teratail.com/questions/v90o6sljcz06ee と同じ質問ですか?
もうひとつの方に回答しました。

投稿2022/01/27 02:18

shiracamus

総合スコア5406

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

suzu

2022/01/27 04:35

ありがとうございました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問