Computer Science With Python
Computer Science With Python
PROGRAM FILE
c=0 OUTPUT:
5
for i in n:
d=int(i)
d=d**2
c=c+d
print(c)
1.
Q2. WAP to print Fibonacci Series (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...) till n
terms. (Accept n from the user)
CODE:
OUTPUT:
n1=0
enter the no of terms u want:10
n2=1
fibonacci series
c=0
0
n=int(input('enter the no of terms u want:'))
1
if n<=0:
1
print('error')
elif n==1: 2
print(n1) 3
else: 5
print('fibonacii series') 8
while c<n: 13
print(n1) 21
d=n1+n2 34
n1=n2
n2=d
c=c+1
2.
Q3. WAP ALL[ ] to two list Odd[ ]and Even[].The Even should contain
values from places (0,2,4,………) of ALL[] and Odd[] should contain
values from places ( 1,3,5,……….).
CODE:
OUTPUT:
ALL=[]
enter the no of terms:5
Even=[]
enter the elements of the list:1
Odd=[]
enter the elements of the list:2
c=int(input('enter the no of terms:'))
enter the elements of the list:3
for i in range(c):
enter the elements of the list:4
l=int(input('enter the elements of the list:'))
enter the elements of the list:5
ALL.append(l)
ALL: [1, 2, 3, 4, 5]
for i in ALL:
Even: [2, 4]
if i%2==0:
Odd: [1, 3, 5]
Even.append(i)
else:
Odd.append(i)
print('ALL:',ALL)
print('Even:',Even)
print('Odd:',Odd)
3.
Q4. Write a code in python and swap the elements of every even
location with its following odd location. Example : If an list of nine
elements initially contains the elements as 2,4,1,6,5,7,9,23,10
rearranges the list as as 4,2,6,1,7,5,23,9,10
CODE:
l=[]
OUTPUT:
c=int(input('enter the no of terms in the list:')) enter the no of terms in the list:6
for i in range(c): enter the elements of the list:1
n=input('enter the elements of the list:') enter the elements of the list:hood
l[i+1]=t
print('new list:',l)
4.
Q5. WAP program to create a list of tuples from given list having
number and its cube in each tuple
CODE:
l=[] OUTPUT:
for i in l:
d=i**3
c.append((i,d))
e=tuple(c)
print(e)
5.
Q6.WAP to create a tuple and display its maximum ,minimum value
and display it in ascending order.
CODE:
l=[]
OUTPUT:
c=[]
enter any number:210
for i in range(3): enter any number:12
n=int(input('enter any number:')) enter any number:68
6.