我试着对一个数的所有因子求和,但这个数本身除外。我写的代码没有使用"elif“。def sum_divisors(n):divisor = 1
if n == 0: else2+3+4+6+9+12+18print(sum_divisors(102)) # Should be sum of 2+3+6+17+34+51
# 114 我得到了答案0,1,630和<
我的书说,对于使用while-循环进行编程,我们必须首先用一个数字初始化,提供提到'while‘的条件,然后在语句后面加上参与循环的语句,直到满足条件,并在循环中增加值。例子:while(i<=10)s = s + i;i++;但是,在奇数求和的情况下,没有显示这样的递增值。而且,奇怪的是(对我来说),我得到了正确的结果w/
number = int(input("please choose your number: "))
number = int(input("Your guess is wrong it was bigger then the generated number, try again: "))
while number < number_to_guessif yes type y, if not you can close the