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

In which type of cellular transport do particles not flow from a high concentration to a low concentration?
What is the volume of a gold nugget that weighs 2.20 kg? The density of gold is 19.28 g/cc.
Why are volcanoes and volcanic activity a good example of system interactions?
software that instructs the computer how to run applications and controls the display/keyboard is known as the
Which of the following correctly describes the relationship depicted in the diagram below? A. the relationship between different plant hormones and their functi
Which of these lines from the play indicates that Brutus fears power will change Caesar? "And, to speak truth of Caesar/I have not known when his affectio
Read the passage! He was not prone to let his wife into his confidence; but at this was an uneasy secret, he willingly shared it with her. All her avarice was
which of the following was a significant challenge in building the panama canal
When did the most recent ice age occur
Consider the expression 8 - 4 + 2. One student says the answer is 2 and another says it is 6. Which student is correct? Explain what went wrong with the student