geekcomputers / geekcomputers/Python
Need help with an infinite loop
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 35.4k
- Fork
- 12.9k
- Merge trung bình
- 2 giờ 37 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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))
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với hàm sum_fivers() và chạy các ví dụ đã được chú thích của hàm, sau đó theo dõi điều kiện vòng lặp và các biến mà nó sử dụng. Hoàn thành nghĩa là xác định được nguyên nhân khiến quá trình thực thi không kết thúc và xác nhận hành vi mong đợi đối với các đầu vào ví dụ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100