#0.List1=[2,4,6] list2=[1,3,5]将List1和List2合并,并升序排列
#sort()函数是List排序的方法,reverse = False是降序True是升序(默认)
List1 = [2,4,6]
List2 = [1,3,5]
List3 = List1 + List2
List3.sort()
print(List3)1
2
3
4
5
6
运行结果:
D:\PyCharmProject\venv\Scripts\python.exe D:/PyCharmProject/Test1/0.py
[1, 2, 3, 4, 5, 6]
Process finished with exit code 01
2
3
4
#1.一个小于100的正整数,它加上100后是一个完全平方数,再加上268又是一个完全平方数。请问该数是多少?
from math import sqrt
for i in range(0,100):
a = sqrt(i+100)
b = sqrt(i+268)
if (a == int(a)) and (b == int(b)):
print(i)1
2
3
4
5
6
7
运行结果:
D:\PyCharmProject\venv\Scripts\python.exe D:/PyCharmProject/Test1/1.py
21
Process finished with exit code 01
2
3
4
#2.从键盘任意获取一串数字,实现让他们错落相加并将结果输出。
#如:12345 错落相加 1+3+5 2+4 最终结果96
123456 错落相加 1+3+5 2+4+6 最终结果912
num = input()
sum1 = sum2 = 0
for i in range(0,len(num),2):
sum1 += int(num[i])
for i in range(1,len(num),2):
sum2 += int(num[i])
print(str(sum1)+str(sum2))1
2
3
4
5
6
7
8
运行结果:
D:\PyCharmProject\venv\Scripts\python.exe D:/PyCharmProject/Test1/2.py
12345
96
Process finished with exit code 01
2
3
4
5
6
#3.从键盘上获取任意一串英文.
实现:
(1)将重复字符去掉
(2)将大写转换成小写,小写转换成大写。
如:abC 处理后 ABc
#upper()把所有字符中的小写字母转换成大写字母
#lower()把所有字符中的大写字母转换成小写字母
#swapcase()大小写转换
#去重
Input1 = input()
Set1 = set(Input1)
print(Set1)
#大小写转换
Input2 = input()
print(Input2.swapcase())1
2
3
4
5
6
7
8
9
10
11
运行结果:
D:\PyCharmProject\venv\Scripts\python.exe D:/PyCharmProject/Test1/3.py
aaaddddsdsdsd
{'d', 'a', 's'}
AAAaaBBBcccC
aaaAAbbbCCCc
Process finished with exit code 01
2
3
4
5
6
7
8
#4完成倒序输出
def function(input1):
intput2 = input1[-1::-1]
return intput2
input1 = input().split(" ")
m = function(input1)
print(m)1
2
3
4
5
6
运行结果:
D:\PyCharmProject\venv\Scripts\python.exe D:/PyCharmProject/Test1/daoxu.py
1 2 3 4 5
['5', '4', '3', '2', '1']
Process finished with exit code 01
2
3
4
5