Using the while loop find sum of the first 50 natural numbers (python language)?
- frombrumLv 71 month ago
there is a better way of adding a list of consecutive numbers by rule
where n1 is the first number n2 is the last and and m is the number of numbers
teach your teacher this as a better and more flexible method
otherwise - do your onw homework
- brilliant_movesLv 71 month ago
Hi, Katherine Gaguancela.
I'm using the number 1 as the starting point for the 50 natural numbers. Depends on how one defines a natural number (see link).
I've used the variable name "total" rather than "sum", which is a reserved word.
n, total = 1, 0
total += n
n += 1
print ("Sum of first 50 natural numbers is", total)