减法竖式
for a in range(1, 10):
for b in range(0, 10):
for c in range(0, 10):
for d in range(0, 10):
if (a * 100 + b * 10 + 4 - c * 10 - d == c) and a != b != c != d:
print("我=", a, "爱=", b, "学=", c, "数=", d)
计算天数(简单)
import time
time1 = input('请输入日期(g格式为:年/月/日):')
time_tuple = time.strptime(time1, '%Y/%m/%d')
print(f"今年第{time_tuple[7]}天")
计算天数(老师版)
y = int(input("请输入年份"))
m = int(input("请输入月份"))
d = int(input("请输入日"))
month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
if y % 4 == 0 and y % 100 != 0 or y % 400 == 0:
month[2] = 29
day = sum(month[0:m]) + d
print(day)
猜数字(设定版)
guess = 0 secret = 56 print("---------欢迎参加猜数字游戏,请开始---------") while guess != secret: guess = int(input("请输入你猜的数字:")) print("你输入的数字是:", guess) if guess == secret: print("恭喜,猜数成功") else: if guess < secret: print("很遗憾,你猜小了") else: print("很遗憾,你猜大了") print("游戏结束") 猜数字(人机版)
print("你总共有三次猜数字的机会")
if int(input("你第一次输入的数字是:")) == 24:
print("恭喜你猜对了")
elif int(input("你第二次输入的数字是:")) == 24:
print("恭喜你猜对了")
elif int(input("你第三次输入的数字是:")) == 24:
print("恭喜你猜对了")
else:
print("猜错了,正确的数字是24")
斐波那契数列
def tuzi(n): if n == 1: return [0] elif n == 2: return [0, 1] else: tutu = [0, 1] while len(tutu) < n: m = tutu[-1] + tutu[-2] tutu.append(m) return tutu print(tuzi(5)) 角谷猜想
def a(n):
A = 0
while n != 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
A += 1
return A
num = int(input("请输入一个正整数"))
print(f"经过{a(num)}次变为1")
太极图
import turtle
turtle.color('black')
turtle.begin_fill()
turtle.circle(200, -180)
turtle.circle(100, 180)
turtle.circle(-100, 180)
turtle.end_fill()
turtle.circle(-200, -180)
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.color('white')
turtle.dot(40)
turtle.penup()
turtle.goto(0, 300)
turtle.pendown()
turtle.color('black')
turtle.dot(40)
turtle.done()