私はPythonには新しく、上記のテーマに関連した少しのプロジェクトを書こうとしました。ロック、ペーパー、はさみの改善:Python 2.7?
どの部分私はそのfunctionailityを失うことなくとして最短のように私のプロジェクトを作るために修正することができ、すなわち:
import random
option = ["rock", "paper", "scissors"];
pc_selection = ["rock", "paper", "scissors"];
pc_move = random.choice(pc_selection)
#-------------------------------------------------------------------------------
def first_condition():
select = raw_input("Please select your choice\n")
print "Your choice:", select
if select in option:
pc_move
print "Computer choice:", pc_move
else:
first_condition()
if select == pc_move:
print "Result: draw"
elif select == "rock" and pc_move == "paper":
print "Result: Computer wins"
elif select == "paper" and pc_move == "scissors":
print "Result: Computer wins"
elif select == "scissors" and pc_move == "rock":
print "Result: Computer wins"
elif select == "rock" and pc_move == "scissors":
print "Result: You win"
elif select == "paper" and pc_move == "rock":
print "Result: You win"
elif select == "scissors" and pc_move == "paper":
print "Result: You win"
first_condition()
私は私のコードは、(最速と賢い)なので、私の質問は非常に効率的ではないことを知っています私のコードの長さを短縮する可能性のある他の関数を使用していますか?
ありがとうございます!
http://codereview.stackexchange.com/ – YOU
「可能な限り効率的」とはどういう意味ですか?修正の容易さ?理解の容易さ?最小のスペース(メモリ)?最小の時間?これらは相互に矛盾する要件ですか? ; - すなわち、 'ルール3:良い、速い、安い - 2つを選ぶ' –
ご清聴ありがとうございます。私が探しているのは、できるだけ不要なものを排除することを目的とした、速くて良いコードです。現時点で私が感じていないことは、自分のコード内にあまりにも多くのエリフがあることです。 –