Hi,
in college we got an homework. The task is to write a program that sum the first consecutive even numbers and that the sum can not exceed 200.
The result would be:
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 + 22 + 24 + 26
Python should “answer” that:
The count of even numbers is: 13
The total is: 182
I am sure that this is an easy task for most of you, but I am a beginner so please be patient .
I am trying for a couple of days now, but I am not able to write the right code.
So far I was able to do this:
from random import *
from math import *
even = 1
value = 0
while even <= 200:
even = (even + 2)
value = value +1
print ("sum of the value: ", even , "number of the value: ", value )
if even == 200:
break;
total = int(input("How many consecutive numbers should I add up not to exceed 200: "))
if total == 5:
print("You calculated correctly: ", value - 1, “consecutive numbers is the correct answer”)
Thank you for your help