9.12python
猜数字
import random
a = random.randint(0, 10)
print(a)
i = 0
while 1:
b = int(input())
if b < a:
print("小了")
i = i + 1
elif b > a:
print("大了")
i = i + 1
else:
print("对了")
i = i + 1
break
————
while 1:
b = int(input())
if b != a:
if b < a:
print("小了")
i = i + 1
elif b > a:
print("大了")
i = i + 1
else:
print("对了")
i = i + 1
break
print("猜了%d次" % i)
# for输出字母个数
# for输出字母个数
i = 0
for x in 'wuhan institute of design and sciences':
if x == ' ':
continue
print(x)
i = i + 1
——
s.strip(='wuhan institute of design and sciences'
s = 'wuhan institute of design and sciences'
s.replace(' ', '')
for x in s.replace(' ', ''):
i = i + 1
print(i)
水仙花数
# 1234
# in range(1,1000)
# x = 123
# a = x // 100 # 百
# b = x // 10%10 # 十
# c = x % 10 # 个
# print(a,b,c)
for x in range(100, 999):
a = x // 100 # 百
b = x // 10 % 10 # 十
c = x % 10 # 个
if x == a * a * a + b * b * b + c * c * c:
print(x)
# print(a,b,c,d)