Commit 6b631fcf by BellCodeEditor

save project

parent 9397f8e6
Showing with 52 additions and 11 deletions
import random
all = ['石头','剪刀','布']
computer = random.choice(['石头','剪刀','布'])
#所有赢了的情况
win = [['石头','剪刀'],['布','石头'],['剪刀','布']]
class Text():
def func_play(self):
ind = input('请输入【0】石头【1】剪刀【2】布')
if ind.isalpha():
try:
raise ValueError('请输入数字')
except ValueError as v:
print(v)
elif ind.isdigit():
ind = int(ind)
if 0<=ind<=2:
play = all[ind]
print('你输入的是%s,电脑输入的是%s'%(play,computer))
if play == computer:
self.a = '平局'
elif [play, computer] in win:
self.a = '你赢了'
else:
self.a = '你输了'
else:
print('请输入0到2之间的数')
print(self.a)
def write_file(self):
with open('wuhan.txt','a',encoding='utf-8') as f:
f.write(self.a+'n')
while True:
t = Text()
t.func_play()
t.write_file()
\ No newline at end of file
...@@ -4,3 +4,13 @@ import random ...@@ -4,3 +4,13 @@ import random
list2=["剪刀","石头","布"] list2=["剪刀","石头","布"]
ji=random.choice(list2) ji=random.choice(list2)
print("计算机出拳:"+ji) print("计算机出拳:"+ji)
if player==ji:
print("平局")
elif player=="石头"and ji=="剪刀":
print("恭喜,你赢了")
elif player=="剪刀"and ji=="布":
print("恭喜,你赢了")
elif player=="布"and ji=="石头":
print("恭喜你,你赢了")
else:
print("很遗憾,你输了")
\ No newline at end of file
if player==computer:
print("平局")
elif player=="石头"and computer=="剪刀":
print("恭喜,你赢了")
elif player=="剪刀"and computer=="布"
print("恭喜,你赢了)
elif player==""and computer=="石头":
print("恭喜你,你赢了")
else:
print("很遗憾,你输了")
\ No newline at end of file
平局n你输了n你输了n你赢了n你赢了n
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment