Python百练(未完)

计算EXCEL横向地址

'''
Function:计算EXCEL地址
Auto:Sherry
Date:2022.1.21
'''
word =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

n = int(input(''))
if n in range(1, 2147483647):
    while True:
        if n <= 26:
            print(word[n-1])
            break
        else:
            if n / 26 <= 26:
                a = n // 26 - 1
                print(word[a],end='')
                n = n - 26
                continue

读取文件并且按需换行

'''
Function:PayTheList
Auto:Sherry
Date:2022-04-08 17:28
'''
f = open("f:\Python_Datebase\PythonTestDate\ListOfSupermarket.txt",encoding='utf-8')
list = []
for line in f:
    line = line.replace("\n", "")
    line = line.replace("     ", ",")
    line = line.replace(" ","")
    print(line)
    line = line.split(",")
    list.append(line)
print(list)

兴趣小组匹配

'''
Function:兴趣小组匹配
Auto:Sherry
Date:2022.1.16
'''
A = "12894792, 92774113, 59529208, 22962224, 02991600, 83340521, 87365045,40818286, 16400628, 39475245, 55933381, 76940287, 61366748, 95631228,17102313, 50682833, 61562613, 87002524, 83062019, 51743442, 61977890,32010762, 69680621, 87179571, 81761697, 32364296, 07833271, 36198035,26588918, 84046668, 43059468, 73191775, 56794101, 00454780, 11141030,10008994, 35072237, 44945158, 53959980, 75758119, 18560273, 35801494,42102550, 22496415, 03981786, 34593672, 13074905, 07733442, 42374678,23452507, 98586743, 30771281, 17703080, 52123562, 05898131, 56698981,90758589, 18238802, 18217979, 04511837, 75682969, 31135682, 55379006,42224598, 98263070, 40228312, 28924663, 11580163, 25686441, 45944028,96731602, 53675990, 03854194, 14858183, 16866794, 40677007, 73141512,32317341, 56641725, 43123040, 15201174, 62389950, 72887083, 76860787,61046319, 06923746, 17874548, 46028629, 10577743, 48747364, 05328780,59855415, 60965266, 20592606, 14471207, 70896866, 46938647, 33575820,53426294, 56093931, 51326542, 94050481, 80114017, 33010503, 72971538,22407422, 17305672, 78974338, 93209260, 83461794, 41247821, 26118061,10657376, 42198057, 15338224, 50284714, 32232841, 26716521, 76048344,23676625, 62897700, 69296551, 59653393, 38704390, 48481614, 69782897,26850668, 37471053, 88720989, 51010849, 94951571, 60024611, 29808329,70377786, 13899299, 09683688, 58218284, 46792829, 97221709, 45286643,48158629, 57367208, 26903401, 76900414, 87927040, 09926730, 01508757,15101101, 62491840, 43802529, "
B = "44894050, 34662733, 44141729, 92774113, 99208727, 91919833, 23727681, 10003409, 55933381, 54443275, 13584702, 96523685, 50682833, 61562613, 62380975, 20311684, 93200452, 23101945, 42192880, 28992561, 18460278,19186537, 58465301, 01111066, 62680429, 23721241, 20277631, 91708977,57514737, 03981786, 81541612, 07346443, 93154608, 19709455, 37446968,17703080, 72378958, 66200696, 30610382, 89586343, 33152171, 67040930,35696683, 63242065, 99948221, 96233367, 52593493, 98263070, 01418023,74816705, 89375940, 58405334, 96731602, 84089545, 16866794, 94737626,01673442, 70548494, 13638168, 08163691, 11106566, 64375392, 40267902,00897705, 56447313, 54532235, 94738425, 66642634, 83219544, 40546096,66924991, 20592606, 96037590, 73434467, 70896866, 91025618, 57892091,08487641, 32500082, 84412833, 23311447, 38380409, 79957822, 72971538,69645784, 91863314, 73099909, 93209260, 83461794, 81378487, 30423273,22233715, 32232841, 26716521, 03511221, 29196547, 58263562, 56233305,52547525, 55812835, 87253244, 52484232, 80837360, 94098464, 52028151,53267501, 66381929, 84381316, 59788467, 09683688, 67082008, 71605255,80654064, 21434307, 45286643, 76556656, 82465821, 57367208, 79218980,48460468, 59170479, 46046391, 43043164, 96544490, 83340521, 70837892, 18926791, 40818286, 28936302, 11489524, 51031183, 73860337, 13241219,09025448, 10718828, 76360986, 26031606, 76558053, 97726139, 46473415, 48406387, 23625539, 86756012, 35164187, 49161302, 78082834, 35072237,08602486, 29815841, 56562216, 77684187, 81751704, 20160464, 50407962, 27786415, 19893526, 00934129, 37759498, 52636463, 25666982, 43262852, 38393436, 02581136, 29323250, 56950657, 05898131, 95286262, 75574581,54057961, 06703896, 90758589, 57782642, 34492535, 41919697, 06395464, 10993500, 81212949, 34017532, 69569396, 99009936, 57129610, 67401593,71044018, 62076698, 29533873, 71936325, 86874388, 26545032, 35695544, 30433724, 53127345, 72887083, 25390873, 63711546, 06923746, 27783723,33199575, 35929698, 16491251, 18276792, 62744775, 92096155, 06336570, 56141974, 73007273, 31416832, 00171057, 64176982, 46938647, 58460388,69972026, 73724304, 27435484, 51568616, 15531822, 47788699, 11818851, 41594694, 83561325, 43107163, 56965375, 10557343, 26118061, 74650126, 90076467, 10657376, 49901436, 03425162, 61164599, 15797769, 05427896,14444084, 36795868, 18079449, 59653393, 72942548, 06763077, 33895610, 94892653, 12085268, 65174140, 79567366, 23020126, 74290047, 13498869, 21696323, 27724594, 54941003, 38229841, 07050068, "
C = "13404901, 39952424, 47847739, 94939581, 13809950, 70966043, 11161555, 17102313, 47079425, 50682833, 74154313, 61562613, 93200452, 37103342,18479435, 32502597, 36198035, 54210010, 73191775, 48358178, 85544503, 05996766, 54651623, 52113220, 27465181, 23871783, 22496415, 54107041, 65899605, 56528700, 82671109, 61176034, 42374678, 51612628, 63329997, 56591652, 04552733, 12789324, 89586343, 51935014, 38611966, 43916409, 70996050, 98263070, 01418023, 65345049, 21734275, 76846198, 71506230, 00833171, 67128139, 41367555, 64769510, 44010700, 16475199, 93164325, 09386162, 95324041, 80688223, 67629139, 79552617, 76219736, 50368644, 45096021, 54972488, 63779011, 28862942, 73145521, 74078605, 66924991, 12806850, 02171001, 70896866, 73434467, 08487641, 44415025, 32500082, 84412833, 83896188, 52243759, 49191410, 38744339, 48079796, 44937032,06267501, 81866886, 38575984, 25978688, 78974338, 41247821, 12356966,64842303, 79127158, 02366944, 68000570, 12426275, 96409230, 00705972,08266503, 83820884, 08831807, 43273308, 23216105, 29196547, 95160161,05553537, 52182214, 32641346, 91553427, 24436506, 77433749, 01979664,52028151, 88985343, 01761499, 76203088, 63237368, 23405334, 59788467,09683688, 67755443, 29946533, 12053603, 00437479, 15200030, 45286643,93537527, 82465821, 57367208, 53899751, 15354933, 97760830, 68933762, 80220545, 01892750, 39868288, 21524323, 69716610, 65083815, 78048499,03227391, 83340521, 87365045, 71720254, 51031183, 89168555, 08503028,37086236, 25103057, 87002524, 22808816, 80928090, 90741678, 15993372,99117082, 49938176, 21755083, 86903426, 87830263, 53959980, 75758119,59781354, 58679691, 25666982, 56307643, 47180521, 62776522, 78136608,44882734, 90758589, 08075999, 66303819, 23480347, 11580163, 87080118,18329165, 92514163, 89404632, 92377859, 03912329, 17499963, 59699979,79876366, 63894807, 37857001, 86003935, 90087123, 29433345, 80298948,61531153, 61046319, 37839841, 19421134, 48747364, 35196916, 62484573,59907079, 36845702, 21631642, 72739317, 26283700, 80114017, 76639390,29154110, 35159758, 47788699, 11818851, 56520669, 36396767, 36031167,83817428, 10657376, 90076467, 14676452, 11024560, 16327605, 76048344,14444084, 95452011, 99612346, 65172562, 84813675, 88618282, 38704390,27998014, 63859011, 33787505, 60024611, 16229880, 13899299, 35240335,29173227, 45036451, 66177893, 82658333, 43100730, 44520187, 74290047,85013538, 09926730, 27724594, 95148523, 20503000, 64390907, 26006953,98116293, 97457666, 29017396, 04634371, 70791589, "
A = A.replace(' ', '')
a = A.split(',')
B = B.replace(' ', '')
b = B.split(',')
C = C.replace(' ', '')
c = C.split(',')
repeat = []
for i in a:
    if i in b and i not in c:
        repeat.append(i)
long = len(repeat)
print(long)

单词分析

'''
Function:单词分析
Auto:Sherry
Date:2022-02-27 19:12
'''
word=input()
a=0
b=[]
for i in word:
    c=word.count(i)
    if c>=a:
        a=c
for j in word:
    if word.count(j)==a:
        b.append(j)
b.sort()
print(b[0])
print(a)

数字的各位平方和循环圈

'''
Function:各位平方和循环圈
Auto:Sherry
Date:
'''
def sp(a):
    a = a.replace('', ' ')
    a = a.split(' ')
    return a

def fun(a):
    while True:
        sum = 0
        for i in range(1, len(a)-1):
            num = int(a[i]) ** 2
            sum += num
        print(sum)
        if sum == 1:
            break
        else:
            fun(a = sp(a = str(sum)))
            
fun(a = sp(a=input('')))

合数数量

'''
Function:合数数量
Auto:Sherry
Date:2022-04-08 16:17
'''
count =0
for i in range(1,2021):
    if i ==1:
        continue
    for j in range(2, i):
        if i % j ==0:
            count +=1
            break
print(count)

回文日期

'''
Function:回文日期
Auto:Sherry
Date:2022-02-27 20:21
'''
n = int(input())

if n >= 10000101 and n <= 89991231:
    while n <= 89991231:
        n +=1
        n = str(n)
        if n[0]==n[7] and n[1]==n[6] and n[2]==n[5] and n[3]==n[4]:
            n = int(n)
            print(n)
            break
        else:
            n = int(n)
    while n <= 89991231:
        n +=1
        n = str(n)
        if n[0] == n[2] == n[5] == n[7] and n[1] == n[3] == n[4] == n[6]:
            n = int(n)
            print(n)
            break
        else:
            n = int(n)

成绩统计

'''
Function:成绩统计
Auto:Sherry
Date:2022-02-27 19:47
'''
students = input()
i = 0
list = []
while i < int(students):
    i += 1
    score = input()
    list.append(int(score))
list1 = []
for i in range(len(list)):
    if list[i] >= 60:
        list1.append(list[i])
list2 = []
for i in range(len(list)):
    if list[i] >= 85:
        list2.append(list[i])
print("{}%".format(round(len(list1)/len(list)*100)))
print("{}%".format(round(len(list2)/len(list)*100)))

承压计算

'''
Function:承压计算
Auto:Sherry
Date:2022.1.21
'''
l = [
    
    [7],
    [5, 8],
    [7, 8, 8],
    [9, 2, 7, 2],
    [8, 1, 4, 9, 1],
    [8, 1, 8, 8, 4, 1],
    [7, 9, 6, 1, 4, 5, 4],
    [5, 6, 5, 5, 6, 9, 5, 6],
    [5, 5, 4, 7, 9, 3, 5, 5, 1],
    [7, 5, 7, 9, 7, 4, 7, 3, 3, 1],
    [4, 6, 4, 5, 5, 8, 8, 3, 2, 4, 3],
    [1, 1, 3, 3, 1, 6, 6, 5, 5, 4, 4, 2],
    [9, 9, 9, 2, 1, 9, 1, 9, 2, 9, 5, 7, 9],
    [4, 3, 3, 7, 7, 9, 3, 6, 1, 3, 8, 8, 3, 7],
    [3, 6, 8, 1, 5, 3, 9, 5, 8, 3, 8, 1, 8, 3, 3],
    [8, 3, 2, 3, 3, 5, 5, 8, 5, 4, 2, 8, 6, 7, 6, 9],
    [8, 1, 8, 1, 8, 4, 6, 2, 2, 1, 7, 9, 4, 2, 3, 3, 4],
    [2, 8, 4, 2, 2, 9, 9, 2, 8, 3, 4, 9, 6, 3, 9, 4, 6, 9],
    [7, 9, 7, 4, 9, 7, 6, 6, 2, 8, 9, 4, 1, 8, 1, 7, 2, 1, 6],
    [9, 2, 8, 6, 4, 2, 7, 9, 5, 4, 1, 2, 5, 1, 7, 3, 9, 8, 3, 3],
    [5, 2, 1, 6, 7, 9, 3, 2, 8, 9, 5, 5, 6, 6, 6, 2, 1, 8, 7, 9, 9],
    [6, 7, 1, 8, 8, 7, 5, 3, 6, 5, 4, 7, 3, 4, 6, 7, 8, 1, 3, 2, 7, 4],
    [2, 2, 6, 3, 5, 3, 4, 9, 2, 4, 5, 7, 6, 6, 3, 2, 7, 2, 4, 8, 5, 5, 4],
    [7, 4, 4, 5, 8, 3, 3, 8, 1, 8, 6, 3, 2, 1, 6, 2, 6, 4, 6, 3, 8, 2, 9, 6],
    [1, 2, 4, 1, 3, 3, 5, 3, 4, 9, 6, 3, 8, 6, 5, 9, 1, 5, 3, 2, 6, 8, 8, 5, 3],
    [2, 2, 7, 9, 3, 3, 2, 8, 6, 9, 8, 4, 4, 9, 5, 8, 2, 6, 3, 4, 8, 4, 9, 3, 8, 8],
    [7, 7, 7, 9, 7, 5, 2, 7, 9, 2, 5, 1, 9, 2, 6, 5, 3, 9, 3, 5, 7, 3, 5, 4, 2, 8, 9],
    [7, 7, 6, 6, 8, 7, 5, 5, 8, 2, 4, 7, 7, 4, 7, 2, 6, 9, 2, 1, 8, 2, 9, 8, 5, 7, 3, 6],
    [5, 9, 4, 5, 5, 7, 5, 5, 6, 3, 5, 3, 9, 5, 8, 9, 5, 4, 1, 2, 6, 1, 4, 3, 5, 3, 2, 4, 1],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
for i in range(1, len(l)):
    for j in range(i + 1):
        if j == 0:
            l[i][j] = l[i][j] + l[i - 1][0] / 2
        elif j == i:
            l[i][j] = l[i][j] + l[i - 1][j - 1] / 2
        else:
            l[i][j] = l[i][j] + l[i - 1][j - 1] / 2 + l[i - 1][j] / 2

print(sorted(l[29]))

'''
sorted(iterable, key=None, reverse=False)
*iterable:可迭代的对象
*key:用来排序的元素,可以通过函数指定
*reverse:排序规则,reverse = True 降序 , reverse = False 升序(默认
'''

拆分计算

'''
Function:拆分计算
Auto:Sherry
Date:2022-04-08 13:50
'''
count = 0
for i in range(1,2021):
    word = str(i)
    for j in word:
        if int(j) == 2:
            count += 1
print(count)

操作二阶魔方

'''
Function:操作二阶魔方
Auto:Sherry
Date:2022.1.15
Test:
    cube[0][0][0] = ['蓝色', '橙色', '白色']
    cube[0][0][1] = ['蓝色', '红色', '白色']
    cube[0][1][0] = ['绿色', '橙色', '白色']
    cube[0][1][1] = ['绿色', '红色', '白色']
    cube[1][0][0] = ['蓝色', '橙色', '黄色']
    cube[1][0][1] = ['蓝色', '红色', '黄色']
    cube[1][1][0] = ['绿色', '橙色', '黄色']
    cube[1][1][1] = ['绿色', '红色', '黄色']
'''
cube = [['蓝色', '橙色', '白色'],
        ['蓝色', '红色', '白色'],
        ['绿色', '橙色', '白色'],
        ['绿色', '红色', '白色'],
        ['蓝色', '橙色', '黄色'],
        ['蓝色', '红色', '黄色'],
        ['绿色', '橙色', '黄色'],
        ['绿色', '红色', '黄色']
        ]
print('初始颜色是:', end='')
for i in range(len(cube[3])):
    print(cube[3][i], end='')
print()
choose = input('请输入按照什么旋转:')

for i in choose:
    if i == 'x':
        a = cube[3][0]
        b = cube[3][1]
        c = cube[3][2]
        cube[3][0] = cube[2][0]
        cube[3][1] = cube[2][2]
        cube[3][2] = cube[2][1]
        cube[2][0] = cube[6][0]
        cube[2][1] = cube[6][2]
        cube[2][2] = cube[6][1]
        cube[6][0] = cube[7][0]
        cube[6][1] = cube[7][2]
        cube[6][2] = cube[7][1]
        cube[7][0] = a
        cube[7][1] = c
        cube[7][2] = b
    if i == 'y':
        a = cube[3][0]
        b = cube[3][1]
        c = cube[3][2]
        cube[3][0] = cube[7][2]
        cube[3][1] = cube[7][1]
        cube[3][2] = cube[7][0]
        cube[7][0] = cube[5][2]
        cube[7][1] = cube[5][1]
        cube[7][2] = cube[5][0]
        cube[5][0] = cube[1][2]
        cube[5][1] = cube[1][1]
        cube[5][2] = cube[1][0]
        cube[1][0] = c
        cube[1][1] = b
        cube[1][2] = a
    if i == 'z':
        a = cube[3][0]
        b = cube[3][1]
        c = cube[3][2]
        cube[3][0] = cube[2][1]
        cube[3][1] = cube[2][0]
        cube[3][2] = cube[2][2]
        cube[2][0] = cube[0][1]
        cube[2][1] = cube[0][0]
        cube[2][2] = cube[0][2]
        cube[0][0] = cube[1][1]
        cube[0][1] = cube[1][0]
        cube[0][2] = cube[1][2]
        cube[1][0] = b
        cube[1][1] = a
        cube[1][2] = c
for i in range(len(cube[3])):
    print(cube[3][i], end='')

求100!内有多少正约数

'''
Function:求100!内有多少正约数
Auto:Sherry
Date:2022-04-08 16:25
'''
def fun(n):
    sum = 1  # 给一个求阶乘的容器
    for i in range(1, n + 1):
        sum *= i
    print(sum)
    return sum

n = fun(100)

list = []

while n not in range(n):  # 保证输出了一个质因数之后继续循环输出质因数
    for j in range(2, n + 1):
        if n % j == 0:
            n = int(n / j)  # 这里写成 n /= j的时候会报错,
            # 因为除法在第二次循环的时候把n变成了浮点数
            if n == 1:  # 这里是输出 1
                print(j)
            else:  # j 一定是素数
                list.append(j)
                print('{} *'.format(j), end=' ')
                print(len(list))
                break

算式900

'''
Function:算式900
Auto:Sherry
Date:2022.1.16
'''
for a in range(10):
    if a == 0:
        continue
    else:
        for s in range(10):
            if s == a:
                continue
            else:
                for d in range(10):
                    if a == d or s==d:
                        continue
                    else:
                        for f in range(10):
                            if f == a or f == s or f ==d:
                                continue
                            else:
                                for g in range(10):
                                    if g == 0 or g==a or g==s or  g==d or g==f:
                                        continue
                                    else:
                                        for h in range(10):
                                            if h ==a or h == s or h==d or h==f  or h==g:
                                                continue
                                            else:
                                                for j in range(10):
                                                    if j ==a or j==s or j==d or j==f or j==g or j==h:
                                                        continue
                                                    else:
                                                        for k in range(10):
                                                            if k==a or k==s or k==d or k==f or k==g or k==h or k==j:
                                                                continue
                                                            else:
                                                                for l in range(10):
                                                                    if l ==0 or l==a or l==s or l==d or l==f or l==g or l==h or l==j or l==k:
                                                                        continue
                                                                    else:
                                                                        for i in range(10):
                                                                            if i==a or i==s or i==d or i==f or i==g or i==h or i==j or i==k or i==l:
                                                                                continue
                                                                            elif ((a*1000+s*100+d*10+f)-(g*1000+h*100+j*10+k))*(l*10+i)==900:
                                                                                print("({}{}{}{}-{}{}{}{})*{}{}=900" .format(a,s,d,f,g,h,j,k,l,i))
                                                

计算贪吃蛇长度

'''
Function:计算贪吃蛇长度
Auto:Sherry
Date:2022.1.16
'''
snack = '''
            +-------------------------------------------------+
            |                                                 |
            |    H######                      ####            |
            |          #                      #  #            |
            |          #                      #  #            |
            |          #     ####             #  #            |
            |          #     #  #             #  #            |
            |          ######@###             #  #            |
            |                #       ####     #  #            |
            |                #       #  #     #  #            |
            |            ####@#######@###     #  #            |
            |            #   #       #        #  #            |
            | T          #####       #        #  #   ##       |
            | #                      #      ###  ### ##       |
            | ################       #      #      ####       |
            |                #       #      #         #       |
            |   ##############       #######@##########       |
            |   #                         ###                 |
            |   ###########################                   |
            +-------------------------------------------------+
        '''
count1 = 0
count2 = 0
for i in snack:
    if i == '#':
        count1 += 1
    elif i == '@':
        count2 += 1
long = count2 * 2 + count1 + 2
print(long)

门牌制作

'''
Function:门牌制作
Auto:Sherry
Date:2022-02-28 15:03
'''
num = 0
for i in range(1,2021):
    i = str(i)
    
    for j in range(len(i)):
        if i[j] == "2":
            num += 1
print(num)

数位排序

'''
功能:数位排序
作者:Sherry
时间:2022.6.21
n = int(input())
m = int(input())
l = []
for i in range(1, n+1):
    l.append(str(i))
print(l)
l = sorted(l, #对l列表排序
           key=lambda x: sum(  #这里调用key关键字并且使用lambda函数  x表示里面的值,sum表示将值求和
               map(int, x)  #便利x并且返回x的整形状态
           ))
print(l[m-1])e
'''
def fun_sum(num):
    sum = 0#初始化和
    while num != 0: #如果不为0则继续下一步
        sum += num % 10 #差分求和
        num = int(num / 10)#求完和之后除以10并向下取整
    return sum    #返回各位数字和

#接收变量
num = int(input())
index = int(input())
#创建列表用来排序
nums = [i for i in range(1, num + 1)]
#根据接收的变量来建立循环次数
for i in range(num):
    #建立比较大小的循环
    for j in range(num - 1 - i):
        #进行判断大小
        if fun_sum(nums[j]) > fun_sum(nums[j + 1]):
            #这里和刚才一样用一个n来充当容器好替换列表前后的值
            n = nums[j]
            nums[j] = nums[j + 1]
            nums[j + 1] = n
#输出所需要的值
print(nums[index - 1])

斐波那契数列求和

'''
功能:生产斐波拉西数列
作者:Sherry
时间:2022.6.21
'''
list = [1, 1]#这里创建前两项
sum = 0#输出化和
n = int(input())#让用户输入多少项
for i in range(n):
    j = list[i] + list[i + 1]   #计算下一项的值
    list.append(j)#将下一项的值放入list
for i in range(len(list)-2):#因为一开始我给出了前两项所以在这范围-2
    sum += list[i]   #计算前n项和
print(sum)  #输出前n项和

玫瑰花数

#功能:输出玫瑰花数
#作者:Sherry
#2022-6-21
# 键入值
Num = 1000
while Num in range(1000, 10000):#建立循环
    x1 = Num % 10       #提出最后一位
    x2 = Num // 10 % 10     #提出倒数第二位  下面依次类推
    x3 = Num // 100 % 10
    x4 = Num // 1000
    Num_sum = x1 ** 4 + x2 ** 4 + x3 ** 4 + x4 ** 4   #算出各位数的四次方和

    #进行比较
    if Num == Num_sum:
        # 若相同则输出  否则直接跳过
        print('{} = {} ^ 4 + {} ^ 4 + {} ^ 4 + {} ^  4'.format(Num, x4, x3, x2, x1))
    #循环次数num+1
    Num += 1

计算纸张尺寸

'''
功能:计算纸张尺寸
作者:Sherry
时间:2022.6.21
'''
#创建列表以判断输入内容是否合格
list = ["A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9"]
cc = input()#创建输入的内容
a = 1189    #初始长
b = 841     #初始宽
#判断是否是正确的输入内容
if cc not in list:
    #如果不是重新运行,这里没有做次数或者死循环
    print("尺寸输入错误")
else:
    #先取出数字---也就是循环次数
    n = int(cc[1])
    #建立循环,次数由输入里面的数字决定
    for i in range(n):
        #判断长边短边  并且对半处理   使用int是因为消耗所以使用向下取整
        if a > b:
            a = int(a/2)
        else:
            b = int(b/2)
    #这里做这个是输出的时候让长边一直在上面输出,所以用了一个c来充当容器并转换   a  ,  b  值
    if a<b:
        c = a
        a = b
        b = c
    print(a)
    print(b)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫腻余腥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值