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

Which state currently has the highest minimum wage? Washington Nevada California
Understand the central concerns that motivated the antifederalists and indicate their economic and political differences with the federalists
4,720 rounded to the nearest thousand
What do the three references to slavery in the Constitution touch on?
what is 4/20 simplified
complete the pattern 9.5 950 95,000
A yard fabric costs $12.99. How much will 2 feet cost?
Which state had the first Labor Day law passed on Feb. 21, 1887? A. New Jersey B. Oregon C. Colorado D. New York
which is another way to write the number 47
Using the scientific method, a(n) _____ must be tested as the focus of any experiment.