T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
count = 0
for i in T:
if type(i) == tuple:
count += 1
print(count)
count = 0
for i in T:
if type(i) == tuple:
count += 1
print(count)
2025-08-11
L = [[1,2,3],[5,3,2],[7,3,2]]
for i in range(len(L)):
a = 1
for j in L[i]:
a *= j
print(a)
for i in range(len(L)):
a = 1
for j in L[i]:
a *= j
print(a)
2025-08-11
_list=[95.5, 85, 59, 66, 72]
_list=sorted(_list,reverse=True)
print(_list[0:3])
_list=sorted(_list,reverse=True)
print(_list[0:3])
2025-08-09
最新回答 / 慕無(wú)忌8377531
num = 0sum = 0while num <= 1000:? ? num = num + 1? ? if num % 2 > 0:? ? ? ? continue? ? sum = sum + num? ? ??print(sum)num作為計(jì)數(shù)器必須保證循環(huán)一次就加1。由于你把加1的語(yǔ)句放到了if條件后面,導(dǎo)致num是1的時(shí)候無(wú)法正常進(jìn)行加1,num永遠(yuǎn)是1,1永遠(yuǎn)小于1000.陷入了死循環(huán)。解決辦法:將num加1的語(yǔ)句放到循環(huán)開(kāi)始的位置,保證每次循環(huán)num都可以加1
2025-08-09
所以這個(gè)課程沒(méi)有結(jié)果效果圖,第一時(shí)間不知道結(jié)果對(duì)不對(duì)
2025-08-08
最新回答 / 慕無(wú)忌8377531
num是計(jì)數(shù)器,控制循環(huán)的次數(shù)。也可以用0,但是用1更直觀。比如控制循環(huán)次數(shù)為20。即為num<20。如果是0,控制循環(huán)次數(shù)為20,即為num<19。
2025-08-06
def greet(n='world!'):
if not isinstance(n, str):
print('Hello,{}'.format(str(n)))
else:
print('Hello,{}'.format(n))
greet()
greet('ccc')
greet(111)
greet((1,2,3,4))
if not isinstance(n, str):
print('Hello,{}'.format(str(n)))
else:
print('Hello,{}'.format(n))
greet()
greet('ccc')
greet(111)
greet((1,2,3,4))
2025-07-30
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
print('-----------')
c_set = set()
if not s2.isdisjoint(s1):
for item in s1:
if item in s2:
c_set.add(item)
print(c_set)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
print('-----------')
c_set = set()
if not s2.isdisjoint(s1):
for item in s1:
if item in s2:
c_set.add(item)
print(c_set)
2025-07-30
不知道對(duì)不對(duì)
a = 3.1415926;
b = 'Learn Python in imooc.';
c = 100;
d = 0b1101;
print(type(a),type(b),type(c),type(d))
a = 3.1415926;
b = 'Learn Python in imooc.';
c = 100;
d = 0b1101;
print(type(a),type(b),type(c),type(d))
2025-07-25
# Enter a code
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L= ([50, 61, 66],[80, 61, 66],[88, 75, 90])
num = 0
for item in d:
d[item] = L[num]
i = num+1
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L= ([50, 61, 66],[80, 61, 66],[88, 75, 90])
num = 0
for item in d:
d[item] = L[num]
i = num+1
print(d)
2025-07-24
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
L = ('Alice', 'Bob', 'Candy', 'Mimi', 'David')
for item in L:
print('{}:{}'.format(item,d.get(item)))
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
L = ('Alice', 'Bob', 'Candy', 'Mimi', 'David')
for item in L:
print('{}:{}'.format(item,d.get(item)))
2025-07-24
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for item in L:
num = 1
for i in item:
num = i*num
print(num)
for item in L:
num = 1
for i in item:
num = i*num
print(num)
2025-07-22
L = ['Alice', 66, 'Bob', True, 'False', 100]
num = 1
for c in L:
if num % 2 == 0:
print(c)
num += 1
num = 1
for c in L:
if num % 2 == 0:
print(c)
num += 1
2025-07-22
age = 19
if age >= 18:
temp = 'adult {}'
print(temp.format(age))
if age >= 18:
temp = 'adult {}'
print(temp.format(age))
2025-07-21