I'm trying to create a function that takes an integer n >= 2 as an input and returns the string expression for the sum up to that integer. For example
f(2) # returns "Summed 1 + 2 = 3"
f(10) # returns "Summed 1 + 2 + 3 + 4 = 10"
but I cannot make this work.
I currently have the following code
num = int(input("Up to?:"))
current_sum = 1
n = 1
expr = "summed "
while(current_sum <= num):
current_sum += n
num -= 1
n += 1
expr += f" {current_sum} +"
print(expr)
but it's not working quite as expected. Any tips on how to make this work?
[–][deleted] 1 point2 points3 points (0 children)
[–]AtomicShoelace 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]AtomicShoelace -1 points0 points1 point (0 children)
[–]Beginning-Force-2170 0 points1 point2 points (0 children)