Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Need help with an infinite loop

未关闭
#2,926 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

从 sum_fivers() 函数开始,运行其中注释掉的示例,然后跟踪循环条件及其使用的变量。完成的标准是确定执行不终止的原因,并确认示例输入的预期行为。

由索引模型根据 Issue 内容生成。

描述

I'm taking a first time programming class and I think I have an infinite loop in my code but can't find it, can anyone help?

Here's the code:
###############################################
#Name:
#Assignment: PA6 -
#Due Date: Wednedday October 13th
#Honor Code Statement: Honor Code Statement: I received no assistance on this
#assignment that violates the ethical guidelines set forth by the professor
#and class syllabus,including any AI or code auto-complete tools.
###############################################

#######################################

Task 1: Write a function called sum_up() that takes an integer and adds up and returns all the integers for 1 up to that number.

#######################################
def sum_up(n):
current_sum = 0
counter = 1
while counter <= n:
current_sum += counter
counter += 1
return counter
#print(sum_up(5))
#print(sum_up(9))

#######################################

Task 2: Write a function called sum_up2() that takes two integers, bottom and top, and adds up and adds up and returns

#######################################
def sum_up2(bottom,top):
total = 0
current_number = bottom
while current_number <= top:
total += current_number
current_number += 1
return total
#print(sum_up2(2,3))
#print(sum_up2(2,2))
#print(sum_up2(15,19))

#######################################

Task 3: Write a function called sum_fivers that takes in integer and adds up all the multiples of 5 that are less than or equal to

#######################################
def sum_fivers(n):
total = 0
current_multiple =5
while current_multiple <= n:
total += current_multiple
return total
#print(sum_fivers(5))
#print(sum_fivers(19))

#######################################

Task 4: Write a function called count_fivers() that takes an integer and counts and returns how many multiples of 5

#######################################
def count_fivers(n):
return n // 5
#print(count_fivers(5))
#print(count_fivers(19))
#print(count_fivers(40))

#######################################

Task 5: Write a function called power_up that takes two values, the first , base, and the second is an integer

#######################################
def power_up(base, exp):
if exp == 0:
return 1.0
result = 1.0
count = 0
if exp > 0:
while count < exp:
result *= base
count += 1
elif exp < 0:
while count > exp:
result *= base
count -= 1
result = 1.0 / result

return(result)
#print(power_up(2,3))
#print(power_up(5,5))

#######################################

Task 6: Write a function called mystery_sum that takes one integer parameter, n, and calculates a "sum"

#######################################
def mystery_sum(n):
total = 0
i = 1
while i < n:
if i % 2 == 0:
total += i**i
else:
total += i * 2
i += 1
return(total)

#print(mystery_sum(4))
#print(mystery_sum(13))

#######################################

Task 7: Write a function called mystery_sum2 that takes one integer parameter, n, and caluculates a sum as follows:

#######################################
def mystery_sum2(n):
total = 0
i = 1
while i < n:
if i % 2 == 0:
total += (i // 2) ** 2
else:
total += i ** 2
i += 1
return(total)
#print(mystery_sum2(4))
#print(mystery_sum2(13))

#######################################

Task 8: Write a function called bigger_mystery() that takes one integer parameter, n, and determines which mystery function above

#######################################

def bigger_mystery(n):
sum1 = mystery_sum(n)
sum2 = mystery_sum2(n)
if sum1 > sum2:
return "ONE"
elif sum2 < sum1:
return "TWO"
else:
return "SAME"

#print(bigger_mystery(5))
#print(bigger_mystery(20))

主要语言
Python
星标
35.4k
派生
12.9k
平均合并
2 小时 37 分钟
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

geekcomputers/Python 的其他 Issue

查看 geekcomputers/Python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。