0% found this document useful (0 votes)
1 views4 pages

Python Assignment 3

The document contains a Python assignment with ten questions that involve basic programming tasks such as printing odd and even numbers, calculating sums, finding factorials, generating Fibonacci sequences, and summing squares. Each question includes code snippets and their corresponding outputs. The assignment is designed to reinforce fundamental programming concepts in Python.

Uploaded by

vani.gera2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Python Assignment 3

The document contains a Python assignment with ten questions that involve basic programming tasks such as printing odd and even numbers, calculating sums, finding factorials, generating Fibonacci sequences, and summing squares. Each question includes code snippets and their corresponding outputs. The assignment is designed to reinforce fundamental programming concepts in Python.

Uploaded by

vani.gera2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Assignment 3

Ans 1.
for i in range (1,101):
if i%2!=0:
print(i)
OUTPUT
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63
65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
Ans 2.
sum=0
for i in range(1,101):
if i%2==0:
sum+=i
print('The sum of the even nos. from 1 to 100 = ',sum)
OUTPUT
The sum of the even nos. from 1 to 100 = 2550
Ans 3.
fact=1
n=int(input('Enter the no.: '))
for i in range(1,n+1):
fact*=i
print('Factorial of',n,'=',fact)
OUTPUT
Enter the no.: 5
Factorial of 5 = 120
Ans 4.
n=int(input('Enter a no.: '))
a,b=0,1
print(a)
print(b)
for i in range(1,n+1):
print(a+b)
z=a
a=b
b=z+b
OUTPUT
Enter a no.: 7
0
1
1
2
3
5
8
13
21
Ans 5.
n=int(input('Enter a no.: '))
for i in range (1,11):
print(i*n)
OUTPUT
Enter a no.: 13
13
26
39
52
65
78
91
104
117
130
Ans 6.
for i in range (2,11,2):
print(i)
OUTPUT
2
4
6
8
10
Ans 7.
for i in range(5,31,5):
print(i)
OUTPUT
5
10
15
20
25
30
Ans 8.
for i in range(-10,0,-3):
print(i)
OUTPUT
-10
-7
-4
-1
Ans 9.
sum=0
for i in range(1,101):
sum+=i**2
print('Sum of squares of first 100 natural nos. = ',sum)
OUTPUT
Sum of squares of first 100 natural nos. = 338350
Ans 10.
n=int(input('Enter a no.'))
for i in range (1,n+1):
if i%2!=0:
print(i)
OUTPUT
Enter a no. 12
1
3
5
7
9
11

You might also like