python3--str的使用1
来源:互联网 发布:java用户昵称随机生成 编辑:程序博客网 时间:2024/06/03 22:45
#字符串
sentence = 'I am an English sentence'
#split默认空格分割字符串,还可以使用换行符\n、制表符\t分割字符串
print (sentence.split())
#split 指定字符串分隔符
section = 'Hi.I am the one.Bye.'
print(section.split('.'))
##罚球游戏以3分定胜负
from random import choice
dircetion= ['L','M','R']
score = [0,0]#computer,person
rounds = 3
flag=False
#首先得到3分者获胜
#定义函数,模拟得分过程
def kick():
you = input('choose you side to shoot:')
#随机取序列中的一个值
com = choice(dircetion)
#com = 'M'
print('your choose is %s,computer‘s choose is %s' %(you.upper(),com))
#使输入大写
if you.upper() == com:
score[0]+=1
else:
score[1]+=1
print('Score is %d(computer) - %d(you)' %(score[0],score[1]))
while(flag == False):
# print('flag=' + flag)
for i in range(rounds):
print('==========Round%d===========' %(i+1))
kick()
#比较值大小‘==’
if score[0] == 3 :
print('computer is the winner!')
flag=True
#跳出for循环,break
break
elif score[1] == 3:
print('you is the winner!')
flag=True
break
else:
rounds+=1
i+=1
print('go on...')
sentence = 'I am an English sentence'
#split默认空格分割字符串,还可以使用换行符\n、制表符\t分割字符串
print (sentence.split())
#split 指定字符串分隔符
section = 'Hi.I am the one.Bye.'
print(section.split('.'))
##罚球游戏以3分定胜负
from random import choice
dircetion= ['L','M','R']
score = [0,0]#computer,person
rounds = 3
flag=False
#首先得到3分者获胜
#定义函数,模拟得分过程
def kick():
you = input('choose you side to shoot:')
#随机取序列中的一个值
com = choice(dircetion)
#com = 'M'
print('your choose is %s,computer‘s choose is %s' %(you.upper(),com))
#使输入大写
if you.upper() == com:
score[0]+=1
else:
score[1]+=1
print('Score is %d(computer) - %d(you)' %(score[0],score[1]))
while(flag == False):
# print('flag=' + flag)
for i in range(rounds):
print('==========Round%d===========' %(i+1))
kick()
#比较值大小‘==’
if score[0] == 3 :
print('computer is the winner!')
flag=True
#跳出for循环,break
break
elif score[1] == 3:
print('you is the winner!')
flag=True
break
else:
rounds+=1
i+=1
print('go on...')
阅读全文
0 0
- python3--str的使用1
- python3 bytes、str的区别
- Python3的bytes/str之别
- Python3的bytes/str之别
- Python3中 bytes/str的区别
- Python3的bytes/str之别
- python3 下ascii与 str的转换
- char** str的使用
- Python3 str数组处理
- Python2 vs Python3: str
- python3中,socket使用send函数时出现的错误:TypeError: a bytes-like object is required, not 'str'
- Python菜鸟晋级02----Python3的bytes与str
- python3.2的bytes和str数据拼接
- python3 list、tuple(元组)、str之间的相互转换
- Python3与Python2的坑之unicode/str
- 关于str函数的使用
- Python3.6 str内置方法
- python3--list的使用
- Java线程-5:线程的同步与锁
- Android—RecyclerView带你飞
- Apache Camel系列(2)----Hello World
- 如何将原型设计的优势发挥到淋漓尽致?
- (UVA
- python3--str的使用1
- mac下配置python的虚拟环境virtualenv和虚拟环境管理包virtualenvwrapper
- Android 快速发布开源项目到jcenter
- session和cookie的区别
- IDEA使用Tomcat和Maven插件启动maven项目的参数配置;
- Java线程-6:线程的交互
- MySQL--操作简记(创建计算字段,数据处理函数(文本,时间日期,数值))
- HDU 6092 Rikka with Subset
- JVM——类文件结构