def digui(n):
if n==1:
return n
else:
return n+digui(n-1)
print(digui(100))
if n==1:
return n
else:
return n+digui(n-1)
print(digui(100))
2024-02-19
def greet(str1:str, str2: str = "world") -> str:
return "{} {}".format(str1, str2)
print(greet("hello", "world"))
print(greet("hello"))
return "{} {}".format(str1, str2)
print(greet("hello", "world"))
print(greet("hello"))
2024-02-17
def greet(ch='world'):
print('Hello,'+ch+'.')
greet()
greet('imooc')
print('Hello,'+ch+'.')
greet()
greet('imooc')
2024-02-17
def sub_num(L):
odd = 0
even = 0
for num in L:
if num%2==0:
even = even + num
else:
odd = odd + num
return odd,even
result = sub_num([1,2,3,4,5])
print(result)
print('奇数项的和={},偶数项的和={}'.format(result[0],result[1]))
odd = 0
even = 0
for num in L:
if num%2==0:
even = even + num
else:
odd = odd + num
return odd,even
result = sub_num([1,2,3,4,5])
print(result)
print('奇数项的和={},偶数项的和={}'.format(result[0],result[1]))
2024-02-16
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
num = len(d.keys())
print(num)
num = len(d.values())
print(num)
print(len(d))
num = len(d.keys())
print(num)
num = len(d.values())
print(num)
print(len(d))
2024-02-15
scores = (100,69,29,100,72,99,98,100,75,100,100,4,88,100)
print(scores.count(100))
print(scores.count(100))
2024-02-15
L = [[1,2,3],[5,3,2],[7,3,2]]
for item in L:
length=item[0]
width=item[1]
height=item[2]
area = length*width*height
print(area)
for item in L:
length=item[0]
width=item[1]
height=item[2]
area = length*width*height
print(area)
2024-02-15
L = ['Alice','Bob','Candy','David','Ellena']
candy = L.pop(2)
David = L.pop(2)
print(candy)
print(David)
print(L)
candy = L.pop(2)
David = L.pop(2)
print(candy)
print(David)
print(L)
2024-02-15
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.append('Zero')
names.insert(5,'Phoebe')
names.insert(5,'Gen')
print(names)
names.append('Zero')
names.insert(5,'Phoebe')
names.insert(5,'Gen')
print(names)
2024-02-15
L = ['Alice',66,'Bob',True,'False',100]
num = 0
for item in L:
num = num +1
if num%2==0:
print(item)
num = 0
for item in L:
num = num +1
if num%2==0:
print(item)
2024-02-14
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x + y + z)
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x + y + z)
2024-02-13
num = 0
sum = 0
while True:
if num > 1000:
break
if num%2!=0:
num = num+1
continue
sum = sum+num
num = num+1
print(sum)
sum = 0
while True:
if num > 1000:
break
if num%2!=0:
num = num+1
continue
sum = sum+num
num = num+1
print(sum)
2024-02-13
num = 0
sum = 0
while True:
if num>1000:
break
if num%2==0:
sum = sum+num
num = num+1
print(sum)
sum = 0
while True:
if num>1000:
break
if num%2==0:
sum = sum+num
num = num+1
print(sum)
2024-02-13