Write Pythonic Code To Check If A 2. Input Five Integers (+ve and Ve)
Write Pythonic Code To Check If A 2. Input Five Integers (+ve and Ve)
given year is a leap year or not. Write Pythonic code to find the sum
Sol: of negative numbers, positive
numbers and print them. Also, find
year=int(input("Enter year to be checked:")) the average of all the numbers and
if(year%4==0 and year%100!=0 or year numbers above average.
%400==0): Sol:
print("The year is a leap year!)
else: n=int(input("Enter the number of
print("The year isn't a leap year!) elements to be in the list:"))
b=[]
for i in range(0,n):
a=int(input("Element: "))
b.append(a)
sum1=0
sum2=0
sum3=0
for j in b:
if(j>0):
if(j%2==0):
sum1=sum1+j
else:
sum2=sum2+j
else:
sum3=sum3+j
print("Sum of all positive even
numbers:",sum1)
print("Sum of all positive odd
numbers:",sum2)
print("Sum of all negative
numbers:",sum3)
3. Write Pythonic code to find Mean,
Variance and Standard Deviation for 3.O/P please :
a list of numbers.
Sol: # initializing list r = lambda q: q * 2
test_list = [4, 5, 8, 9, 10] s = lambda q: q * 3
x=2
# printing list
print("The original list : " + x = r(x)
str(test_list)) x = s(x)
x = r(x)
# Standard deviation of list print x
# Using sum() + list comprehension
mean = sum(test_list) /
len(test_list) i)42
variance = sum([((x - mean) ** 2) ii)24
for x in test_list]) / iii)12
len(test_list)
res = variance ** 0.5 iv)Code will not run
# Printing result
print("Standard deviation of sample
is : " + str(res))
i) SCOE
ii)scoe
iii)true
iv)false