20200712学员答疑贴

20200712 提问1:这个你好像没讲

解答1:

20200712 提问2:简历生成 Demo

# -------------- user_input --------------
username_input = input("请输入你的姓名:")
susersex_input = input("请输入你的性别:")
userage_input = input("请输入你的年龄:")
userschool_input = input("请输入你的学校:")

# -------------- Print --------------
print("正在生成你的简历......")
# print("*****************************")
print("*"*20)
print("\t简历")
print("姓名:{}".format(username_input))
print("性别:" + susersex_input)
print("年龄:{}".format(int(userage_input)))
print("毕业学校:" + userschool_input)
print("*"*200000)

补充知识点:字符串格式化输入输出(2020-07-14)

str1 = "He{a}l{b}lo"
str2 = "World!"
# print(str1 + str2)
print(str1.format(b = "-", a = "你"))
He你l-lo
x = "北京大学"
y = "清华大学"
# str_text = "2020年,高考你将考上{},祝贺你!".format(x)
str_text = f"2020年,高考你将考上{x},{y}祝贺你!"
print(str_text)
2020年,高考你将考上北京大学,清华大学祝贺你!
# x = "北京大学"
# y = "清华大学"
# # str_text = "2020年,高考你将考上{},祝贺你!".format(x)
# str_text = f"2020年,高考你将考上:%s,祝贺你!"str(&x)
  File "<ipython-input-4-92f2d1c2f097>", line 4
    str_text = f"2020年,高考你将考上:%s,祝贺你!"str(&x)
                                        ^
SyntaxError: invalid syntax

AI悦创:补充字符串格式化

print("你好,我是:%s" % "悦创")

print("今年:%d" % 1)

print('你好,我是:%s : AI悦创的字符串长度是:%s' % ("AI悦创", len("AI悦创")))
你好,我是:悦创
今年:1
你好,我是:AI悦创 : AI悦创的字符串长度是:4

题目解答:

image-20200717202318578

str1 = "132569874"
translat_list = list(str1)
print(translat_list)
['1', '3', '2', '5', '6', '9', '8', '7', '4']
enven_number = translat_list[::2]
print(enven_number)
enven_number.sort(reverse = True)
print(enven_number)
['1', '2', '6', '8', '4']
['8', '6', '4', '2', '1']
translat_list[::2] = enven_number
print(translat_list)
['8', '3', '6', '5', '4', '9', '2', '7', '1']