请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生

【Python 第27课】 list切片

[复制链接]

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2016-12-7 17:23:18 |显示全部楼层
l0ve1o24 发表于 2016-12-7 12:57
老师,我运行你的代码的时候 第二回合还是显示round1

点球大战,每一轮是踢一次再守一次,两个都是第一轮
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

8

积分

新手上路

Rank: 1

发表于 2016-12-8 00:54:58 |显示全部楼层
虽然不会写但我就想吐个槽啊,点球哪来的平手 没出胜负要一直罚下去吧
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2016-12-8 15:05:29 |显示全部楼层
sunxin2006 发表于 2016-12-8 00:54
虽然不会写但我就想吐个槽啊,点球哪来的平手 没出胜负要一直罚下去吧

这个程序是可以扩展的啦
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

8

积分

新手上路

Rank: 1

发表于 2016-12-11 21:02:10 |显示全部楼层
crossin先生 发表于 2016-12-8 15:05
这个程序是可以扩展的啦

老师说的对,自己还在慢慢啃…太痛苦了以前学的C++全交给大学老师了
回复

使用道具 举报

0

主题

0

好友

56

积分

注册会员

Rank: 2

发表于 2017-9-23 22:14:59 |显示全部楼层
from random import choice

score_you=0
score_com=0
direction=['左边','中间','右边']

for i in range(5):
    print('====开始你的回合====')
    print('选择一波射门')
    print('左边','中间','右边')
    you=str(input())
    print('你射向了'+you)
    com=choice(direction)
    print('电脑扑向了'+com)
    if you!=com:
        print('球进了!')
        score_you+=1
    else:
        print('糟糕..')
    print('得分:%s(you),%s(com)'%(score_you,score_com))
    print('====开始你的回合====')
    print('选择一边射门')
    print('左边','中间','右边')
    you=str(input())
    print('你射向了'+you)
    com=choice(direction)
    print('电脑扑向了'+com)
    if you==com:
        print('电脑扑到了球')
    else:
        print('糟糕...')
    score_com+=1
print('得分:%s(you),%s(com)'%(score_you,score_com)

这个会有一个逻辑错误但我不知道该怎么改,而且有时候计分会出现问题,我是3.5版本的
求老师看看怎么改
QQ截图20170923221437.png
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2017-9-23 23:44:40 |显示全部楼层
努力的小白 发表于 2017-9-23 22:14
from random import choice

score_you=0

什么逻辑错误?从你的截图没看出来
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

56

积分

注册会员

Rank: 2

发表于 2017-9-24 11:22:37 |显示全部楼层
向左边射门,电脑扑向中间,显示还是被扑到了
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2017-9-24 12:20:38 |显示全部楼层
努力的小白 发表于 2017-9-24 11:22
向左边射门,电脑扑向中间,显示还是被扑到了

那把文件编码改成 gbk
#coding:gbk
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

60

积分

注册会员

Rank: 2

发表于 2017-10-25 15:10:03 |显示全部楼层
  1. from random import choice
  2. direction = ['left', 'center', 'right']
  3. print('欢迎来到点球大赛')
  4. player=0 #分数初始化
  5. computer=0
  6. for i in range(5): #5次循环等价于range(0, 5);
  7.     #你踢

  8.     print("Round%s---你踢,电脑守" % (i + 1))
  9.     you = input('请选择方向:left, center, right\n')
  10.     print('你踢向 ' + you)
  11.     com = choice(direction)
  12.     print('Computer扑向%s'%com)
  13.     if you != com:
  14.         print('Goal!你的得分+1')
  15.         player = player + 1

  16.     else:
  17.         print('Oops..很可惜,电脑得分+1.')
  18.         computer = computer + 1
  19.     print('Score%d(you) - Score%d(cp)' % (player, computer))
  20.     #电脑踢
  21.     #print('欢迎来到点球大赛')
  22.     print("Round%s---你守,电脑踢" % (i + 1))
  23.     you = input('请选择方向:left, center, right\n')
  24.     print('你扑向' + you)
  25.     com = choice(direction)
  26.     print('电脑踢向' + com)
  27.     if you == com:
  28.         print('Goal!你的得分+1')
  29.         player = player + 1
  30.     else:
  31.         print('Oops..可惜,电脑+1.')
  32.         computer = computer + 1
  33.     print('Score:%d(you) - Score:%d(cp)' % (player, computer))
复制代码
回复

使用道具 举报

0

主题

2

好友

72

积分

注册会员

Rank: 2

发表于 2018-4-7 11:29:13 |显示全部楼层
从昨天琢磨到今天,按照各位大神函数的方法,写了下面这个,锻炼了自己函数这部分吧,话说,,你们太狠了,佩服
  1. #football_game.py
  2. #司南 2018.04.07
  3. #方向设定
  4. direction=['left','middle','right']
  5. #扑救方
  6. def keeper(name='computer'):
  7.     import random
  8.     dic=random.choice(direction)
  9.     if name=='computer':
  10.         print('天哪,快看,守门员扑向了%s方向' %dic)
  11.     else:
  12.         print('天哪,快看,守门员%s扑向了%s方向' %(name,dic))
  13.     return dic
  14. #射门方
  15. def shoot(man):
  16.     dic=input('请输入射球方向:left/middle/right')
  17.     print('快看,%s能否射进呢?' %man)
  18.     return dic
  19. #比赛规则
  20. def fight(keeperdic,shootdic):
  21.     if keeperdic==shootdic:
  22.         print('omg,the goalkeeper win!')
  23.         return True
  24.     else:
  25.         print('天哪,球进了!!')
  26.         return False
  27. #开始比赛
  28. score_keeper=0
  29. score_shoot=0
  30. man=input('Hei,man please tell us your name:')
  31. round=eval(input('how many round do you do'))
  32. for i in range(round):
  33.     print('====Everybody the %dth round begin!===='%(i+1))
  34.     shootdic=shoot(man)
  35.     keeperdic=keeper()
  36.     res=fight(keeper,shootdic)
  37.     if res:
  38.         score_keeper=score_keeper+1
  39.     else:
  40.         score_shoot=score_shoot+1
  41. #判断总分胜负:
  42. if score_keeper>score_shoot:
  43.     print('伟大的守门员赢啦!!')
  44. elif score_keeper<score_shoot:
  45.     print('%s 你赢啦!'%man)
  46. else:
  47.     print('平手!')
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-3-29 23:53 , Processed in 0.036406 second(s), 25 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部