
Lv.1
我可以接受失败但绝不能接受未奋斗过的自己(现在在神岛玩交朋友加QQ:2514644742)
签名: 代码岛: 地图:《迷雾逃杀》《黑夜障碍赛车》《山谷冰川湖泊》 模组:《战士头盔》 名字:唯爱_耿直的阿尔法贺嘉豪(记得关注哦!)
在 【Python作品分享】@9_谁先算到20【作品秀】 中回复
imgsrc="https://static.codemao.cn/emotion/thunder_monkey/%E6%91%87%E6%A4%85%E5%AD%90240.gif"alt="emotion_雷电猴_摇椅子"
2022-02-24T19:58:16 点赞:1
在 【Python作品分享】家灵cAZd 建议后的作品【作业帖】 中回复
我试了一下你的这个,我玩完后,显示的是“玩家赢了”同时和“电脑赢了”有点问题imgsrc="http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/e9/sk_thumb.gif"alt="emotion_思考"imgsrc="http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/e9/sk_thumb.gif"alt="emotion_思考"imgsrc="http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/e9/sk_thumb.gif"alt="emotion_思考" importtime importturtle importrandom __Pen=turtle.Pen() time.sleep(1) a=0 mypen=turtle.Pen() length=200 mypen.pensize(40) mypen.pencolor('lightsalmon') mypen.forward(length) mypen.pensize(30) mypen.pencolor('white') mypen.backward(length) #出数总和 total=0 while(total<20): #玩家输入整数 myscreen=turtle.Screen() try: player_num=int(turtle.textinput('谁先达到20!','请输入1~3范围的整数:')) if(player_num>3): print('请输入1~3范围的整数!') else: print('玩家出的信息',player_num) mypen.pencolor('mistyrose') mypen.forward((player_num*10)) total=(total+player_num) print("总和:",total) if(total==20): print('玩家赢了!') elif(total>20): print('玩家输了!') else: #电脑随机出整数 com_num=random.randint(1,3) print('电脑出的数',com_num) mypen.pencolor('salmon') mypen.forward((com_num*10)) total=(total+com_num) print('总和:',total) if(total==20): print('电脑赢了!') elif(total>20): print('电脑输了!') else: print('-----------------') exceptValueError: print('请输入整数!') mypen.hideturtle() turtle.done()
2022-02-28T19:40:01 点赞:1
在 【Python作品分享】家灵cAZd 建议后的作品【作业帖】 中回复
elif play[0] == play[1] == play[2] == 'X':
print('你输了')
d = 1
elif play[3] == play[4] == play[5] == 'O':
print('你赢了')
d = 1
elif play[3] == play[4] == play[5] == 'X':
print('你输了')
d = 1
elif play[6] == play[7] == play[8] == 'O':
print('你赢了')
d = 1
elif play[6] == play[7] == play[8] == 'X':
print('你输了')
d = 1
elif play[0] == play[3] == play[6] == 'O':
print('你赢了')
d = 1
elif play[0] == play[3] == play[6] == 'X':
print('你输了')
d = 1
elif play[1] == play[4] == play[7] == 'O':
print('你赢了')
d = 1
elif play[1] == play[4] == play[7] == 'X':
print('你输了')
d = 1
elif play[2] == play[5] == play[8] == 'O':
print('你赢了')
d = 1
elif play[2] == play[5] == play[8] == 'X':
print('你输了')
d = 1
elif play[0] == play[4] == play[8] == 'O':
print('你赢了')
d = 1
elif play[0] == play[4] == play[8] == 'X':
print('你输了')
d = 1
elif play[2] == play[4] == play[6] == 'O':
print('你赢了')
d = 1
elif play[2] == play[4] == play[6] == 'X':
print('你输了')
d = 1
我觉得这里可以简化
2022-02-28T19:42:40 点赞:1
在 【Python作品分享】家灵cAZd 建议后的作品【作业帖】 中回复
import turtle
import random
myscreen = turtle.Screen()
mypen = turtle.Pen()
mypen.hideturtle()
mypen.penup()
mypen.goto(-112.5 , 0)
mypen.pendown()
count = 0
p_win = 0
c_win = 0
flag = False
while count < 10 :
player = int(myscreen.textinput("剪刀1-石头2-布3","请输入猜拳对应的数字:"))
computer = random.randint(1 , 3)
if player == 1:
print("玩家出了,剪刀")
elif player == 2:
print("玩家出了,石头")
elif player == 3:
print("玩家出了,布")
else :
print("玩家输入数字超出范围")
flag = True
if computer == 1:
print("计算机出了,剪刀")
elif computer == 2:
print("计算机出了,石头")
else:
print("计算机出了,布")
#判断胜负
if player == computer or flag:
print("此局平局或废局")
mypen.pencolor("gray")
mypen.dot(20)
flag = False
elif player == 1 and computer == 3 or player == 2 and computer == 1 or player == 3 and computer == 2:
print("此局玩家胜")
p_win = p_win + 1
mypen.pencolor("darkgreen")
mypen.dot(20)
elif player == 3 and computer == 1 or player == 1 and computer == 2 or player == 2 and computer == 3:
print("此局计算机胜")
c_win = c_win + 1
mypen.pencolor("red3")
mypen.dot(20)
mypen.penup()
mypen.forward(25)
mypen.pendown()
count = count + 1
print("--------------")
print("玩家的胜局数为:" , p_win)
print("计算机的胜局数为:", c_win)
turtle.done()
2022-03-02T18:48:51 点赞:0