目录
1.输入一个整数判断奇数偶数
2.判断一个数是否能被7或11整除但不能同时整除
3.判断某一年是否为闰年:能被4整除但不能被100整除,或者能被400整除
4.《车辆驾驶人员血液、呼气酒精含量阈值与检验》标准中规定:驾驶员血液酒精小于20mg/100ml 不构成酒驾,大于或等于20mg/ml、小于80mg/ml为饮酒驾驶则暂扣6个月机动车驾驶证、1000~2000元罚款、一次记12分;驾驶员血液酒精大于或等80mg/ml为醉酒驾驶则约束至酒醒、吊销驾驶证、5年内不得重新获取驾驶证、追究刑事责(注意:饮用350mL(约相当于1小瓶)啤酒或半两白酒(20ml)后,血液酒精浓度可达20mg/100ML,即达到饮酒驾驶的处罚条件)
5.输入三个整数,降序输出
6.输入一个百分制成绩,根据输出等级成绩
7.计算1+2+3+4+5+……+100之和
计算下列多项式之和:1+1/2+1/3+1/4+··· ···+1/100
计算下列多项式之和:1-1/2+1/3-1/4+1/5··· ···1/n
计算下列多项式之和:1+1/(1+2)+1/(1+2+3)+··· ···+1/(1+2+··· ···+n)
计算a+aa+aaa+a...a前六项之和(a=2)
用泰勒级数计算e的近似值,直到最后一项小于1e-6为止,e=1+1/1!+ 1/2! +1/3!+……1/n!
计算Π的计算公式,Π/4 = 1-1/3+1/5-1/7+...计算Π的近似值。
break语句:终止当前循环,执行循环外下一跳语句(终止循环)一般和if语句进行搭配使用,例:计算r=1到r=10时的圆面积,直到面积area大于100为止
continue语句作用:跳出当前循环剩余语句,继续执行下一循环(加速循环),一般与if语句搭配使用,例:将100到150之间的不能被3整除的数输出,要求一行输出10 个数
for-else结构:for循环执行完或者未进入循环(即 for 不是通过 break 跳出而中断的)的情况下执行else,例
输入一个整数,判断是否为素数
输出100以内的素数
输出200-400中的非素数
输出大于m且紧随m的k个素数
输出100以内能被9整除余数为2的数,并计算其平均值的平方根
输出水仙花数
输出1000以内的完数(完数:因子之和等于原值)
输出100以内的同构数(若一个正整数出现在它的平方数的尾部)
判断回文数字
求整数a和b 的最小公倍数
求整数x和y 的最大公约数
用户在键盘输入一个4位整数,转换为英文,如:输入1024,为One Zero Two Four
古典问题:有一对兔子,从出生后第三个月都生一对兔子,小兔子到第三个月每个月又都生一对兔子,假设兔子不死,问12个月每个月兔子总数多少(Fibonacci数列:1 1 2 3 58)
计算Fibonacci数列中大于t的最小值
有一张足够大的纸,厚0.09mm,问对折多少次厚可以达到珠穆朗玛峰的高度(8448m)迭代 ( 27次 )
爱因斯坦阶梯问题:有多级阶梯,每步跨2阶余1阶,每步跨3阶余2阶,每步跨5阶余4阶,每步跨6阶余5阶,每步跨7阶正好到顶,则共有多少阶
百钱买买百鸡问题
搬砖问题:36人搬36块砖,男搬4块,女搬3块,2个小孩抬一块砖,一次搬完,需要男、女、小孩各多少人
猴子偷桃:一天吃了一般还要多吃一个,第七天吃完,问一共偷桃几何?
打印图形
#方法一
num = int(input("请输入数字:"))
if num % 2 == 1:
print("奇数")
else:
print("偶数")
方法二
num = int(input("请输入数字:"))
if (num % 7 == 0 or num % 11 == 0) and num % 77 != 0:
print("yes")
else:
print("no")
year = int(input("请输入四位数年份:"))
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print("闰年")
else:
print("平年")
proof = int(input("请输入100ml血液的酒精含量:"))
if proof < 20:
print("不构成酒驾,请注意安全!")
else:
if proof < 80:
print("酒驾,暂扣6个月机动车驾驶证、1000~2000元罚款、一次记12分")
else:
print("醉驾,约束至酒醒、吊销驾驶证、5年内不得重新获取驾驶证、追究刑
事责任")
a = int(input())
b = int(input())
c = int(input())
if a > b:
if a > c:
if b > c:
print(a, b, c)
else:
print(a, c, b)
else:
print(c, a, b)
else:
if a > c:
print(b, a, c)
elif b > c:
print(b, c, a)
else:
print(c, b, a)
x>=90 优秀
90>x>=80 良好
80>x>=60 及格
x<60 补考
num = int(input("请输入百分制成绩:"))
if num > 100 or num < 0:
print("数据错误,请输入0-100范围内数字!")
elif num >= 90:
print("优秀")
elif num >= 80:
print("良好")
elif num >= 60:
print("及格")
else:
print("补考")
# while 循环
sum = 0
i = 1
while i <= 100:
sum += i
i += 1
print("sum=", sum)
# for 循环
sum = 0
for i in range(101):
sum += i
print("sum=", sum)
sum = 0
for i in range(1, 101):
sum = sum + 1 / i
print("sum=%.6f" % sum)
sum = 1
f = -1
for i in range(2, 101):
sum = sum + 1 / i * f
f = -f
print("sum=%.6f" % sum)
sum = 0
t = 0
for i in range(1, 101):
t = t + i
sum = sum + 1 / t
print("sum=%.6f" % sum)
a = 2
sum = 0
for i in range(6):
sum = sum + a
a = a * 10 + 2
print("sum=", sum)
sum = 1
t = 1
i = 1
while 1 / t > 1e-6:
t = t * i
sum = sum + 1 / t
i += 1
print("sum=%.6f" % sum)
pi = 1
f = -1
i = 3
while 1 / i > 1e-6:
pi = pi + 1 / i * f
i = i + 2
f = -f
print("pi=%.6f" % (pi * 4))
import math
for r in range(1, 11):
area = math.pi * r * r
if area > 100:
break
print("r: ", r, "area is : %.6f" % area)
i = 0
for n in range(100, 151):
if n % 3 == 0:
continue
print(n, end=" ")
i += 1
if i % 10 == 0:
print("\n")
for i in range(1, 100):
if i % 2 == 0 and i % 3 == 0 and i % 5 == 0:
print("%d 是2、3、5的最小公倍数" % i)
break
else:
print("未找到")
方法一:
prime = int(input("请输入一个整数:"))
if prime < 2:
print("请输入大于2的正整数!")
else:
for i in range(2, prime):
if prime % i == 0:
print("平数")
break
else:
print("素数")
方法二:
i = 2
prime = int(input("请输入一个整数:"))
if prime < 2:
print("请输入大于2的正整数!")
else:
while prime % i:
i = i + 1
if i == prime:
print("素数")
else:
print("平数")
for i in range(2, 100):
for j in range(2, i):
if i % j == 0:
break
else:
print(i, end=" ")
t = 0
for i in range(200, 400):
for j in range(2, i):
if i % j == 0:
print(i, end=" ")
t = t + 1
break
if t % 10 == 0:
print("\n")
m = int(input("请输入起始值m:"))
k = int(input("请输入需要的素数个数k:"))
t = 0 # 计数
i = m + 1
while t < k:
for j in range(2, i):
if i % j == 0:
break
else:
t = t + 1
print(i, end=" ")
i = i + 1
aver = 0
t = 0
for i in range(100):
if i % 9 == 2:
print(i, end=" ")
aver += i
t += 1
print("\n aver=%.2f" % ((aver / t) ** 0.5)) # aver=6.86
for i in range(100, 1000):
if (i % 10) ** 3 + (i // 10 % 10) ** 3 + (i // 100) ** 3 == i:
print("水仙花数:", i)
for i in range(6, 1000):
sum = 0
for j in range(1, i):
if i % j == 0:
sum += j
if i == sum:
print(i, end="\t")
for i in range(100):
if i * i % 10 == i or i * i % 100 == i:
print(i, end=" ")
m = int(input("请输入数字:"))
n = m
t = 0
while n > 0:
t = t * 10 + n % 10
n //= 10
if t == m:
print("yes")
else:
print("no")
#方法一
a = int(input("输入第一个数:"))
b = int(input("输入第二个数:"))
i = 1
while 1:
if i % a == 0 and i % b == 0:
print(i)
break
i += 1
#方法二
a = int(input("输入第一个数:"))
b = int(input("输入第二个数:"))
i = 0
while 1:
i += a
if i % b == 0:
print(i)
break
x = int(input("输入第一个数:"))
y = int(input("输入第二个数:"))
lcm = x * y # lcm 为最小公倍数
while x % y != 0:
t = x % y
x = y
y = t
gcd = y # gcd 为最大公约数
lcm = lcm // gcd
print("最大公约数:", gcd, "最小公倍数:", lcm)
m = int(input("请输入正四位整数:"))
t = 1000
if m >= 1000 and m < 10000:
while t > 0:
if m // t % 10 == 0:
print("Zero", end=" ")
elif m // t % 10 == 1:
print("One", end=" ")
elif m // t % 10 == 2:
print("Two", end=" ")
elif m // t % 10 == 3:
print("Three", end=" ")
elif m // t % 10 == 4:
print("Four", end=" ")
elif m // t % 10 == 5:
print("Five", end=" ")
elif m // t % 10 == 6:
print("Six", end=" ")
elif m // t % 10 == 7:
print("Seven", end=" ")
elif m // t % 10 == 8:
print("Eight", end=" ")
elif m // t % 10 == 9:
print("Nine", end=" ")
t //= 10
else:
print("请输入四位正整数")
a1 = 1
a2 = 1
for i in range(6):
print(a1, a2, end=" ")
a1 = a1 + a2
a2 = a1 + a2
a1 = 0
a2 = 1
a3 = 1
t = int(input("请输入一个正整数:"))
while a3 <= t:
a1 = a2
a2 = a3
a3 = a1 + a2
print("最小值:", a3)
t = 0
tl = 0.09e-3
while 1:
t = t + 1
tl = tl * 2
if tl >= 8848:
break
print("次数:", t)
i = 7
while 1:
if i % 2 == 1 and i % 3 == 2 and i % 5 == 4 and i % 6 == 5:
break
i += 7
print("阶数:", i)
for cocks in range(101):
for hens in range(101):
for chicks in range(101):
if cocks + hens + chicks == 100 and cocks * 5 + hens * 3 +
chicks // 3 == 100 and chicks % 3 == 0:
print("公鸡=", cocks, "母鸡=", hens, "小鸡=", chicks)
for m in range(10):
for w in range(13):
for c in range(0, 73, 2):
if m + w + c == 36 and m * 4 + w * 3 + c // 2 == 36:
print("男:", m, "女:", w, "孩:", c)
n = 0
for i in range(7):
n = (n + 1) * 2
print(n)
h = int(input('请输入图形高度:'))
for i in range(h):
for j in range(h - i - 1):
print(' ', end='')
for k in range(2 * i + 1):
print('*', end='')
print()