Computer Science, asked by vasugoel2772, 3 months ago

WAP in python enter 10 numbers in a tuple from keyboard, then display sum of all negative odd numbers.

Answers

Answered by TEJASWEE148
1

Answer:

# Python program to print negative odd Numbers in a List  

 

# list of numbers  

list1 = [10, -21, 4, -45, -66, 92]  

 

# iterating each number in list  

for num in list1:  

     

   # checking condition  

   if num % 2 != 0:  

      print(num, end = " ")

Copy this and try it...Hope it helps....If doesnt then comment I will correct it.

Answered by Anonymous
3

Answer:

#Program by ankitraj707

lst=[]

neg_odd=0

n=10 #enter 10 numbers as given in the question

print('Enter 10 numbers')

for i in range(n):

   lst.append(int(input())) #make a list of the entered number

 

for j in lst:

if j<0 and j%2!=0: #condition for being negative and odd

 neg_odd+=j

           

print("sum of all negative odd integers:{}".format(neg_odd))

#See the output in the attachment

OR

nums= input("Input 10  comma separated numbers : ")

neg_odd=0

list = nums.split(",")

tup = tuple(list)

tup=[int(i) for i in tup]

print(tup)

for j in tup:

if j<0 and j%2!=0:

 neg_odd+=j

           

print('sum of all negative odd integers is',neg_odd)

#this one is simple than the above

#thanks for such questions, I also learned something which I  had forgot...lol

Attachments:
Similar questions