''' 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-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-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-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)