Python Forum
[Learning] 3 hours for one simple exercise
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Learning] 3 hours for one simple exercise
#8
This is the entire code resolved. I will leave the answer here. Sorry for being late!

def calc(n):
    i = 1
    total = 0
    if (1 <= n <= 100):
        for i in range(1, n+1, 4):
            aux = i**2
            total = aux + total
    else:
        total = -1
    return total;
    

# Program
num=int(input("Input number "))

sum = calc (num)

if (sum==-1):
    print("The number is not in range")
else:
    print("The total of the calc is: ", sum)
Reply


Messages In This Thread
RE: [Learning] 3 hours for one simple exercise - by KoFu - Sep-08-2019, 09:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plz help Ive tried for hours and cant do these three problems VB4 1 1,989 Mar-17-2018, 04:59 AM
Last Post: micseydel
  Simple exercise - how to write in python tomtom55 6 4,999 Sep-28-2017, 07:18 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020