02-Borigh-摸底「意大利」
原创2023年2月4日大约 4 分钟...约 1249 字
Question1: 问答式简历生成
# first
name = input('请输入你的姓名:')
gender = input('请输入你的性别:')
age = int(input('请输入你的年龄:'))
university = input('请输入你的学校:')
print('正在生成你的简历......')
print('*'*20)
print('\t简历')
print(f'姓名:{name}')
print(f'性别:{gender}')
print(f'年龄:{age}')
print(f'毕业学校:{university}')
Question2: 运势推演
Borghi Answer
# second
gender = input('请输入你的性别(F/M):').upper()
age = int(input('请输入你的年龄:'))
if gender == 'F' and age == 17:
print('你会考上清华并找到一个男盆友')
else:
print('请重新输入')
aiyuechuang
import random
# print(random.randint(1, 3))
luck = ["考上清华大学", "赢取白富美", "变有钱"]
unluck = ["摔倒", "放屁", "钱少1元"]
yunshi_data = [luck, unluck]
result = random.choice(yunshi_data)
# print(result)
username = input("name:>>>")
age = int(input("age:>>>"))
gender = input("gender:>>>")
if (age > 18) and (gender.upper() == "F"):
print(random.choice(result))
else:
print("aiyc")
Question3: 字符串最后一个单词的长度
Borghi Answer
# fourth-1
while True:
str = input('输入一行,代表要计算的字符串,非空,长度小于 5000:')
if str == ' ' or len(str) > 5000:
print('请重新输入.输入一行,代表要计算的字符串,非空,长度小于 5000:')
else:
str_new = str.split(' ')
print(int(len(str_new[-1])))
aiyuechuang
s = input() # 输入字符串 s
arr = s.split(" ") # 以空格分割字符串并将结果存入数组 arr
print(len(arr[-1])) # 打印最后一个元素 arr[-1] 的长度即为最后一个单词的长度
s = input() # 输入字符串 s
if len(s) <= 5000:
arr = s.split(" ") # 以空格分割字符串并将结果存入数组 arr
print(len(arr[-1])) # 打印最后一个元素 arr[-1] 的长度即为最后一个单词的长度
Question4:计算某字符出现次数
Borghi Answer
# fourth-2
str_1 = input('输入一个由字母和数字以及空格组成的字符串:')
str_2 = input('输入一个字符:')
str_total = str_1 + str_2
print(str_1.count(str_2))
aiyuechuang
s1 = input().lower()
s2 = input().lower()
print(s1.count(s2))
Question5: 中山大学
Borghi Answer
with open('mid_score.txt.txt', mode='rt', encoding='utf-8') as f:
info = f.readlines()
for i in range(len(info)):
info[i] = info[i].strip()
info[i] = info[i].split()
print(info)
for i in range(len(info)):
for j in i:
score_total = info[j]
# print(score_total)
aiyuechuang
# # 学号 语文 数学 英语
#
# def read_function(path):
# with open(path, "r", encoding="utf-8") as f:
# return f.readlines()
#
#
# def parse(contents):
# pass
#
# if __name__ == '__main__':
# path = "mid_score.txt"
# contents_lst = read_function(path)
# parse(contents_lst)
# 学号 语文 数学 英语
# from pprint import pprint
import pprint
def read_function(path):
data_dict = {}
# str_to_int = lambda lst: map(int, lst[1:])
with open(path, "r", encoding="utf-8") as f:
contents_lst = f.readlines()
# print(contents_lst)
for line in contents_lst:
new_line = line.strip("\n").strip(" ")
line_list = new_line.split(" ")
# print(line_list)
id, yuwen, shuxue, yy = line_list
data_dict[id] = int(yuwen) + int(shuxue) + int(yy)
pprint.pprint(data_dict)
path = "mid_score.txt"
read_function(path)
添加写入
# # 学号 语文 数学 英语
#
# def read_function(path):
# with open(path, "r", encoding="utf-8") as f:
# return f.readlines()
#
#
# def parse(contents):
# pass
#
# if __name__ == '__main__':
# path = "mid_score.txt"
# contents_lst = read_function(path)
# parse(contents_lst)
# 学号 语文 数学 英语
# from pprint import pprint
import pprint
def read_function(path):
data_dict = {}
# str_to_int = lambda lst: map(int, lst[1:])
with open(path, "r", encoding="utf-8") as f:
contents_lst = f.readlines()
# print(contents_lst)
for line in contents_lst:
new_line = line.strip("\n").strip(" ")
line_list = new_line.split(" ")
# print(line_list)
id, yuwen, shuxue, yy = line_list
data_dict[id] = int(yuwen) + int(shuxue) + int(yy)
# pprint.pprint(data_dict)
sort_by_value = list(data_dict.items())
sort_by_value.sort(key=lambda x: x[1], reverse=True)
print(sort_by_value)
with open("data.txt", "w+", encoding="utf-8") as f:
for tup in sort_by_value:
f.write(str(tup) + "\n")
# sorted_by_value = sorted(data_dict.items(), )
path = "mid_score.txt"
read_function(path)
lambada
字典排序
demo
# -*- coding: utf-8 -*-
# @Time : 2023/2/4 17:46
# @Author : AI悦创
# @FileName: demo.py
# @Software: PyCharm
# @Blog :https://bornforthis.cn/
def read_file(path):
with open(path, "r", encoding="utf-8") as f:
return f.readlines()
def parse(content_list, split_fuhao=" "):
d_data = []
for line in content_list:
lst = line.strip().split(split_fuhao)
d_data.append(lst)
# print(dict(d_data))
return dict(d_data)
def select(opt1, opt2):
result_list = []
# for t in opt1.items():
# print(t)
for key, value in opt1.items():
# print(key, value)
result_list.append((value, opt2[key]))
print(result_list)
name_score = read_file("name_score.txt")
name_pinyin = read_file("name_pinyin.txt")
name_score_d = parse(name_score)
name_pinyin_d = parse(name_pinyin, split_fuhao=",")
select(name_pinyin_d, name_score_d)
公众号:AI悦创【二维码】
AI悦创·编程一对一
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
方法一:QQ
方法二:微信:Jiabcdefh
你认为这篇文章怎么样?
- 0
- 0
- 0
- 0
- 0
- 0