Professional Documents
Culture Documents
1) Write a program to input the value of x and n and print the sum
of the following series:
i) 1+x+x^2+x^3+......x^n
ii) 1-x+x^2-x^3+......x^n
1) 1+x+x^2+x^3+......x^n
In [4]:
Sum = 31.0
2) 1-x+x^2-x^3+......x^n
In [5]:
Sum = 11.0
In [1]:
Sum = 10.666666666666666
In [1]:
Sum = 6.0
In [3]:
• If the employee is a male and age is in between 20-40, then he may work anywhere,
• If the employee is male and age is between 40-60 then he'll work in urban areas only,
In [14]:
4) Take integer inputs from the user until he/she presses q (Ask to
press q to quit after every integer input). Print average and
product of all numbers.
In [9]:
a = []
b=0
while b!='q':
i = int(input('Enter a number: '))
b = input('Do u want to quit?(Press q if yes): ')
a.append(i)
avg = sum(a)/len(a)
product = 1
for x in a:
product*=x
print()
print('Average of given numbers: ', avg)
print('Product of given numbers: ', product)
Enter a number: 34
Enter a number: 45
Enter a number: 24
Enter a number: 96
Enter a number: 35
Sum of digits= 21