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 of the drugs below is known as the date rape drug due to its depressant qualities? oxycodone ritalin valium rohypnol
The _____________ is the contract that seals the deal when you buy a car. A. loan application B. warranty C. loan agreement D. sales agreement
Identify the subordinate clause. The book that I am reading concerns world population problems. the book the book that I am reading book that I am reading that
how do you find the mean in the list 46, 38, 53, 34,27, 54?
Which of the following information is not provided in most dictionaries? part of speech definition quotes pronunciation
Is 1/3 bigger than 1/2
preserved remains have turned to what?
Which side does these following words go ? : orange, dragon, engine,digit ?
In marks collection of antique bottles 1/2of the bottle are dark green write three equivalent fractions for 1/2
Which of the following items is not considered a stimulant? a. alcohol b. nicotine c. caffeine d. cocaine