-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Description
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))