s = '''
《Dehors Dreams》
123451
In the quiet night, under a silver moon,
Dreams take their flight王大拿, and hearts(( )[]{ }) start to bloom.
张三、李四往外
Stars above shine(。) so bright, like diamonds in the night,
Guiding our path, in their gentle light.
Together we walk, hand in hand, through life's twist and turns,
With every step, our love just burns.
点号包括句号(。)、问号(?)、叹号(!)、逗号(,)、顿号(、)、分号(;)、冒号(:)。
标号包括引号(""' ')、括号(( )[]{ })、破折号(------)、省略号(......)、着重号(.)、连接号(---、~、-等)、间隔号(・)、书名号(《 》〈 〉)。
Let's make a promise🐔, here and now,
To cherish each moment, and never let it go.
With you😂, my love, there's no doubt,
Our hearts will stay young, forever🚀 in love's embrace.
'''.lower()
s
print(s)
# 循环字符串中的每一个字符
# 判断是否在 a - z 之间
# 如果在累积起来
# 如果累积成一个完整的单词把它放在字典里
# 定义变量保存单词的每一个字母
t = ''
# 定义字典保存单词和出现的次数
dict_ = {}
for i in s:
if 'a' <= i <= 'z' or i == "'":
t += i
elif t != '':
if dict_.get(t):
dict_[t] += 1
else:
dict_[t] = 1
t = ''
dict_
python复制代码
s = '''
《Dehors Dreams》
123451
In the quiet night, under a silver moon,
Dreams take their flight王大拿, and hearts(( )[]{ }) start to bloom.
张三、李四往外
Stars above shine(。) so bright, like diamonds in the night,
Guiding our path, in their gentle light.
Together we walk, hand in hand, through life's twist and turns,
With every step, our love just burns.
点号包括句号(。)、问号(?)、叹号(!)、逗号(,)、顿号(、)、分号(;)、冒号(:)。
标号包括引号(""' ')、括号(( )[]{ })、破折号(------)、省略号(......)、着重号(.)、连接号(---、~、-等)、间隔号(・)、书名号(《 》〈 〉)。
Let's make a promise🐔, here and now,
To cherish each moment, and never let it go.
With you😂, my love, there's no doubt,
Our hearts will stay young, forever🚀 in love's embrace.
'''.lower()
t = ''
dict_ = {}
for i in s:
if '一' <= i <= '龥':
t += i
elif t != '':
if dict_.get(t):
dict_[t] += 1
else:
dict_[t] = 1
t = ''
dict_
s = '''200
388
123
456
987
342
767
234
124
345
123
234'''
vals = [int(i) for i in s.split('\n')]
print(vals)
data = {i + 1 : vals[i] for i in range(len(vals))}
print(data)
# 输入正确的开始月份和结束月份
while 1:
start = input('请输入开始月份:')
if start.isdigit():
start = int(start)
if 1 <= start <= 12:
break
print('您输入的月份不合法')
print('您输入的不是数字')
pass
# 输入正确的结束月份和结束月份
while 1:
end = input('请输入结束月份:')
if end.isdigit():
end = int(end)
if start <= end <= 12:
break
print('您输入的月份不合法')
print('您输入的不是数字')
pass
# 计算平均访客量
sum_ = 0
for k in range(start, end + 1):
sum_ += data[k]
avg_ = sum_ / (end - start + 1)
print(start if start == end else f'{start} ~ {end}', f'月平均访客量是:{avg_}', sep = '')
python复制代码
# 输入工龄
while 1:
n = input('请输入工龄:')
if n.isdigit():
n = int(n)
if n >= 1:
break
print('输入的工龄不合法')
if n < 5:
print('年假 1 天')
elif 5 <= n <= 10:
print('年假 5 天')
else:
print('年假 7 天')
python复制代码
import random
# 定义一个集合保存红球
red_ball = set()
while len(red_ball) < 6:
n = random.randint(1, 33)
red_ball.add(n)
# 蓝球
blue_ball = random.randint(1, 16)
# 把集合转为列表
red_ball = list(red_ball)
red_ball = [f'0{i}' if i < 10 else f'{i}' for i in red_ball]
# 排序
red_ball.sort()
print(red_ball)
print(f'中奖号码是:\n红球:{red_ball}\n蓝球:{f"0{blue_ball}" if blue_ball < 10 else f"{blue_ball}"}')
python复制代码
import random
# 定义一个集合保存红球
red_ball = set()
while len(red_ball) < 6:
n = random.randint(1, 33)
red_ball.add(n)
# 蓝球
blue_ball = random.randint(1, 16)
# 把集合转为列表
red_ball2 = list(red_ball)
red_ball2 = [f'0{i}' if i < 10 else f'{i}' for i in red_ball]
# 排序
red_ball2.sort()
print(red_ball)
print(f'中奖号码是:\n红球:{red_ball2}\n蓝球:{f"0{blue_ball}" if blue_ball < 10 else f"{blue_ball}"}')
# 输入中奖号
red_user_ball = set()
while len(red_user_ball) < 6:
while 1:
n = input(f'请输入第{len(red_user_ball) + 1}个红球:')
if n.isdigit():
n = int(n)
if 1 <= n <= 33:
break
print('输入的范围不正确')
else:
print('输入的不是数字')
red_user_ball.add(n)
while 1:
blue_user_ball = input(f'请输入蓝球:')
if blue_user_ball.isdigit():
blue_user_ball = int(blue_user_ball)
if 1 <= blue_user_ball <= 16:
break
print('输入的范围不正确')
else:
print('输入的不是数字')
# 计算中奖号码个数
blue_count = 1 if blue_user_ball == blue_ball else 0
red_count = len(red_ball.intersection(red_user_ball)) # 交集
if blue_count == 1 and red_count == 6:
print(f'恭喜您中了一等奖,奖金浮动')
elif blue_count == 0 and red_count == 6:
print(f'恭喜您中了二等奖,奖金浮动')
elif blue_count == 1 and red_count == 5:
print(f'恭喜您中了三等奖,奖金 3000 元')
elif blue_count == 0 and red_count == 5 or blue_count == 1 and red_count == 4:
print(f'恭喜您中了四等奖,奖金 200 元')
elif blue_count == 0 and red_count == 4 or blue_count == 1 and red_count == 3 :
print(f'恭喜您中了五等奖,奖金 10 元')
elif blue_count == 1 and red_count == 2 or blue_count == 1 and red_count == 1 or blue_count == 1 and red_count == 0:
print(f'恭喜您中了六等奖,奖金 5 元')
else:
print('下次再来')
python复制代码
# 联系人的信息
# 姓名
# 电话
# 邮箱
# 地址
# 需要把 4 条信息保存在字典中
# key: 姓名
# val: 其他
# 定义初始化的数据
data = {
'泽': ['13012345678', '[email protected]', '北京市海淀区'],
'海': ['13012345679', '[email protected]', '北京市海淀区'],
'杰': ['13012345688', '[email protected]', '北京市海淀区'],
'帅': ['13012345670', '[email protected]', '北京市海淀区'],
}
while 1:
msg = '1.添加联系人\n'\
'2.查看联系人\n'\
'3.修改联系人\n'\
'4.删除联系人\n'\
'0.退出\n'\
'请选择:'
while 1:
n = input(msg)
if n.isdigit():
n = int(n)
if 0 <= n <= 4:
break
print('输入的数字不在范围内')
else:
print('输入的不是数字')
match n:
case 0:
break
case 1:
name = input('请输入联系人姓名:')
if name not in data:
phone = input('请输入电话:')
email = input('请输入邮箱:')
address = input('请输入地址:')
data[name] = [phone, email, address]
print('添加成功')
pass
else:
print('联系人已存在')
pass
case 2:
print('姓名\t电话\t\t邮箱\t\t\t地址')
for k, v in data.items():
print(f'{k}\t', '\t'.join(v), sep = '')
pass
case 3:
a = ['电话', '邮箱', '地址']
while 1:
msg = '\n'.join([f'{i + 1}. 修改' + a[i] for i in range(len(a))]) + '\n请选择:'
n = input(msg)
if n.isdigit():
n = int(n)
if 0 <= n <= 3:
break
print('输入的数字不在范围内')
else:
print('输入的不是数字')
name = input('请输入姓名:')
if name in data:
data[name][n - 1] = input('请输入' + a[n - 1] + ': ')
print('修改成功')
pass
else:
print('联系人不存在')
pass
case 4:
name = input('请输入姓名:')
if name in data:
data.pop(name)
print('删除成功')
pass
else:
print('联系人不存在')
pass
print('*' * 60)
# 在终端执行,control + c 是退出