小测验 - 电子组培训文档 #3
Replies: 2 comments
-
第一题: zhihu = 0
l = [0, 1]
n = int(input("请输入一个整数:"))
for i in range(2, n):
zhihu = l[i-1] + l[i-2]
l.append(zhihu)
print(l) |
Beta Was this translation helpful? Give feedback.
0 replies
-
第二题: n = int(input("请输入一个整数:"))
if n < 2:
print("不是素数")
else:
for i in range(2, n):
if n % i == 0:
print("不是素数")
break
else:
print("是素数") 第三题: n = int(input("请输入一个3位数:"))
if n < 10 or n > 99:
print("不是水仙花数")
else:
a = n // 100
b = (n % 100) // 10
c = n % 10
if a ** 3 + b ** 3 + c ** 3 == n:
print("是水仙花数")
else:
print("不是水仙花数") 第四题: n = int(input("请输入一个整数:"))
m = n
reverse = 0
while m > 0:
reverse = reverse * 10 + m % 10
m //= 10
if n == reverse:
print("是回文数")
else:
print("不是回文数") 第四题:
第五题: import random
for i in range(1, 101):
a = random.randint(1, 100)
b = random.randint(1, 100)
operator = random.choice(['+', '-'])
if operator == '+':
answer = a + b
else:
answer = a - b if a >= b else b - a
print(f"{i}. {a} {operator} {b} = {answer}") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
小测验 - 电子组培训文档
https://mr-addict.github.io/Doc-Share/Python/Chapter8.html
Beta Was this translation helpful? Give feedback.
All reactions