# task
sum = 0
num = 0
while num < 1001:
if num % 2 == 0:
num += 1
sum += num
else:
num += 1
continue
print(sum)
sum = 0
num = 0
while num < 1001:
if num % 2 == 0:
num += 1
sum += num
else:
num += 1
continue
print(sum)
2024-03-15
# common deal
num = 1
sum = 0
while True:
if num > 1000:
break
num += 1
if num % 2 == 0:
sum += num
print(sum)
#250500
#########################################
# another deal
sum_2 = 0
for i in range(0,1001,2):
sum_2 += i
print(sum_2)
#250500
num = 1
sum = 0
while True:
if num > 1000:
break
num += 1
if num % 2 == 0:
sum += num
print(sum)
#250500
#########################################
# another deal
sum_2 = 0
for i in range(0,1001,2):
sum_2 += i
print(sum_2)
#250500
2024-03-15
result = 1
for i in range(1, 11):
result *= i
print(result)
for i in range(1, 11):
result *= i
print(result)
2024-03-04
# Enter a code
length = 3.14
width = 1.57
square = length * width
print(round(square, 2))
length = 3.14
width = 1.57
square = length * width
print(round(square, 2))
2024-03-03
# Enter a code
template = 'Life is {w},you need {y}'
result = template.format(w = 'short',y = 'python')
print(result)
template = 'Life is {w},you need {y}'
result = template.format(w = 'short',y = 'python')
print(result)
2024-02-27
最新回答 / 慕标2526337
在Python中,赋值运算符 = 和比较运算符 < 的优先级虽然不同,但在表达式 score=59<60 中,并不是按照优先级解析的。这是因为赋值运算符 = 和比较运算符 < 无法直接这样组合起来成为一个合法的表达式。Python解析器会从左到右扫描表达式,当它遇到 score= 时,它会认为这是一个赋值操作的开始,因此会首先执行赋值操作 score=59,将59赋给变量 score。然而,赋值操作完成后,剩下的 <60 部分由于缺少左边的操作数,导致这个表达式是非法的,Pytho...
2024-02-27
最新回答 / 执剑人程心
因为两者指向同一个列表对象,如:list = [1, 2, 3]list1 = listlist1.append(4)print('list1', list1)print('list', list)list1 [1, 2, 3, 4]list [1, 2, 3, 4]要避免这种情况,使用copy,如:list2 = list.copy()print('list2', list2)list2.append(100)print('list2', list2)print('list', list)list2 [...
2024-02-26
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