Tamannagaur20 Tamannagaur20
  • 01-11-2021
  • Computers and Technology
contestada

Can someone help me write a code in python to find the sum of all the odd numbers from 1-301.
In which python makes a list of all the odd numbers and uses a loop

Respuesta :

arinaaznaureni
arinaaznaureni arinaaznaureni
  • 01-11-2021

arr = []  #an empty array

for i in range(302):  

   arr.append(i) if i%2 != 0 else None #add a new element, if its odd, else - nothing

print(sum(arr)) #printing the sum of elements

Answer Link

Otras preguntas

How do i solve 3v + 1 + 7v = -12
Effects of unsustainable economic growth
How to find Two equivalent fractions of 1/7
how many buses do you need for 700 people if each bus holds 125 people
i have no idea what i am doing
Please I need help on this and take your time please
Work attached. Its just a quick question.
The dot plots show the number of hours a lightbulb lasts from two different brands.which of the following is correct?
State two conditions for the formation of H30​
If there was a dramatic increase in skeletal muscle cell damage and apoptosis, what would you expect to happen to levels of myoglobin and CK in the blood