018
0.1 5 6 7 8 9
1.
18
2.
5
3.
wrong
4.
-250
5.
break
------------------dds
0.
for n in range(100,1000):
a = n//100
b = (n - 100*a)//10
c = n - 100*a -10*b
if n == a**3+b**3+c**3:
print(n,"is number of daffodils")
1.
x = int(input("请输入一个正整数:"))
#if当x小于0的情况 # or # 当x不是0,且x的最后一位为0的情况 #:
if x < 0 or x != 0 and x%10 == 0:
print("不是回文数。")
else:
revertedNumber = 0
y = x
# 请在此处填写一个正确的循环语句 #:
while x != 0:
revertedNumber = revertedNumber * 10 + x % 10
print('*',revertedNumber)
x //= 10
print('-',x)
if y == revertedNumber or y == revertedNumber // 10:
print("是回文数。")
else:
print("不是回文数。")
******************************
0.
0 1 2 3 4 5 6 7 8 9
5.continue
0.
for i in range(100, 1000):
sum = 0
temp = i
while temp:
sum = sum + (temp % 10) ** 3
temp //= 10
if sum == i:
print(i)
1.
x = int(input("请输入一个正整数:"))
if x < 0 or (x % 10 == 0 and x != 0):
print("不是回文数。")
else:
revertedNumber = 0
while x > revertedNumber:
revertedNumber = revertedNumber * 10 + x % 10
x //= 10
if x == revertedNumber or x == revertedNumber // 10:
print("是回文数。")
else:
print("不是回文数。") def foo(n):
r = False
i = n
k = 0
while i:
k = k * 10 + i % 10
i //= 10
if k == n:
r = True
return r
x = int(input("请输入一个正整数:"))
if foo(x):
print('是回文数')
else:
print('不是回文数') # 水仙花數 (Narcissistic Number)
print(f"Narcissistic Number:", *)**3) + (eval(str(i))**3) + (eval(str(i))**3) == i])
# 回文字符串/整數 (Palindrome String/Integer)
strs = "abcdedcba"
if strs == strs[::-1]:
print(f"{strs} is a Palindrome String")
num = 123454321
if num == int(str(num)[::-1]):
print(f"{num} is a Palindrome Integer")Narcissistic Number: 153 370 371 407
abcdedcba is a Palindrome String
123454321 is a Palindrome Integer
页:
[1]