欢迎来到Cefler的博客😁
🕌博客主页:折纸花满衣
🏠个人专栏:题目解析
目录
- 👉🏻百钱买百鸡
- 👉🏻鸡兔同笼
- 👉🏻最大公约数和最小公倍数
- 👉🏻判断三角形并计算面积
- 👉🏻回文素数
- 👉🏻今天是第几天
- 👉🏻判断火车票座位
👉🏻百钱买百鸡
list = []
for i in range(1,20):for j in range(1,32):for m in range(3,97,3):if (i+j+m)!=100:continuenum = (5*i+j*3+m/3)# print(i,j,m,num)if num == 100:tmp = [i,j,m]list.append(tmp)
#排序listlist.sort(key=lambda x:x[0])
for em in list:print(em[0],em[1],em[2])
👉🏻鸡兔同笼
a,b = map(int,input().split())
for i in range(a+1):for j in range(a+1):if i+j==a and i*2+j*4==b:Flag = Trueprint(i,j)exit()
print("Data Error!")
👉🏻最大公约数和最小公倍数
def f1(a,b):while b!=0:k = a%b a = b b = k return a
def f2(a,b):k = max(a,b)while True:if k%a==0 and k%b==0:return k k+=1
a = int(input())
b = int(input())
print(f1(a,b),f2(a,b))
👉🏻判断三角形并计算面积
import math
a = float(input())
b = float(input())
c = float(input())if a+b>c and a+c>b and b+c>a:p = (a+b+c)/2s = math.sqrt(p*(p-a)*(p-b)*(p-c))print("YES\n{:.2f}".format(s))
else:print("NO")
👉🏻回文素数
import math
def fun(n):if n <= 1:return Falsefor i in range(2, int(math.sqrt(n)) + 1):if n % i == 0:return Falsereturn True
if __name__ == '__main__':n = int(input())count = 0i = 0while True:if str(i)==str(i)[::-1]:if fun(i)==True:count += 1print(i, end=" ")if count ==n:breaki+=1
👉🏻今天是第几天
from datetime import datetime
y = input("")
m = input("")
d = input("")
date = y+"-"+m+"-"+d
date_object = datetime.strptime(date,"%Y-%m-%d")
day_of_year = date_object.timetuple().tm_yday
print("{0}年{1}月{2}日是{3}年第{4}天".format(y,m,d,y,day_of_year))
👉🏻判断火车票座位
import re
while True:s = input("")seat = s[-1]pattern = r'\b(1[0-7]|[1-9])[a-zA-Z]\b'if re.match(pattern, s) is None:print("输入错误")exit()if seat == 'A' or seat == 'a' or seat == 'F' or seat == 'f':print("窗口")elif seat == 'c' or seat == 'C' or seat == 'd' or seat == 'D':print("过道")else:print("输入错误")