geekcomputers / geekcomputers/Python
Need help with an infinite loop
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 35.4k
- フォーク
- 12.9k
- 平均マージ
- 2時間 37分
- マージ済み PR(30日)
- 1
説明
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))
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
sum_fivers() 関数から始めて、コメントアウトされた例を実行し、その後、ループ条件とそれが使用する変数を追跡します。終了条件は、実行が終了しない原因を特定し、例の入力に対する期待される動作を確認することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100