Computer PROGRAMS A2Z XI
Computer PROGRAMS A2Z XI
'''
Enter a word : tamanna
orginal string= tamanna
reverse string= annamat
'''
'''
Enter a number : 1234
REVERSE OF 1234 = 4321
'''
'''
Enter year :1999
year is not leap year
'''
'''
Enter a number : 1221
REVERSE OF 1221 = 1221
1221 is a palindrome
'''
'''
enter any no ?20
Fibonacci series !
0 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,= 10945
'''
'''
asending order of for loop
1,3,5,7,9,
desending order of for loop
9,7,5,3,1,
'''
CHECK CREDIT CARD NUMBER
a=int(input('enter a credit card no '))
b=a
s1=0
s2=0
l=[]
i=0
while a>0:
x=a%10
l.append(x)
i+=1
a=a//10
print()
print('a=',a)
print('orginal no=',b)
print('no of digits =',i)
print(l)#87654321
for j in range(0,i,2):
s1+=l[j]
print('sum of odd position no =',s1)
for j in range(0,i,2):
x=l[j+1]**2
print('sqr of no=',x)
while x>0:
p=x%10
s2+=p
#print('sum=',s2)
x=x//10
print('sum of odd position no =',s2)
'''
enter a credit card no 12345678
a= 0
orginal no= 12345678
no of digits = 8
[8, 7, 6, 5, 4, 3, 2, 1]
sum of odd position no = 20
sqr of no= 49
sqr of no= 25
sqr of no= 9
sqr of no= 1
sum of odd position no = 30
'''
'''
'''
Enter the no. of elements in a list: 5
Enter a number:10
Enter a number:20
Enter a number:30
Enter a number:40
Enter a number:50
Sum of the elements of the list= 150
'''
'''
Enter the no. of elements in a list: 6
Enter a number:1
Enter a number:2
Enter a number:3
Enter a number:4
Enter a number:5
Enter a number:6
Sum of the even numbers of the list= 12
'''
Sum of the odd numbers of the list
l=[]
n=int(input("Enter the no. of elements in a list: "))
for i in range(n):
a=int(input("Enter a number:"))
l.append(a)#l=l+[a]
so=0
for i in l:
if i%2!=0:
so+=i
print("Sum of the odd numbers of the list= ",so)
'''
Enter the no. of elements in a list: 5
Enter a number:12
Enter a number:8
Enter a number:55
Enter a number:23
Enter a number:78
Sum of the odd numbers of the list= 78
'''
Modify a list
l=[]
#input the elements of the list
n=int(input("Enter the no. of elements in a list: "))
for i in range(n):
a=int(input("Enter a number:"))
l.append(a)
le=[]
lo=[]
for i in l:
if i%2==0:
le.append(i)
else:
lo.append(i)
print("ORIGINAL LIST: ",l)
print(" EVEN NUMBERS OF THE LIST: ",le)
print(" ODD NUMBERS OF THE LIST: ",lo)
'''
Enter the no. of elements in a list: 5
Enter a number:1
Enter a number:2
Enter a number:3
Enter a number:4
Enter a number:5
ORIGINAL LIST: [1, 2, 3, 4, 5]
EVEN NUMBERS OF THE LIST: [2, 4]
ODD NUMBERS OF THE LIST: [1, 3, 5]
'''
'''
'''
'''
Enter a name:tamanna mohan
do u want to enter more names (y/n)? y
Enter a name:mohan singh
do u want to enter more names (y/n)? y
Enter a name:tushar mohan
do u want to enter more names (y/n)? h
printing direct list : ['tamanna mohan', 'mohan singh', 'tushar mohan']
'''
BINARY SEARCH
l=[10,20,30,45,46,75,80,89,100,200]
y=eval(input('enter the no to be searched :?'))#100
l1=len(l)
lb=0
ub=l1-1
j=0
while (lb<=ub and j==0):
mid=(lb+ub)//2#4,7,8
if y>l[mid]:#T
lb=mid+1#5,8
elif y<l[mid]:
ub=mid-1
else:
j+=1#1
pos=mid#8
print('List :',l)
if j>0:
print(y,'is present ',pos,' in the list')
else:
print(y,'is not present in the list')
'''
enter the no to be searched :?46
List : [10, 20, 30, 45, 46, 75, 80, 89, 100, 200]
46 is present 4 in the list
'''
l= [1, 2, 3]
orginal l2= [5, 6, 7, [1, 2, 3]]
new l2= [5, 6, 7, [1, 2, 3]]
'''
PATTERN-1
for i in range(1,10):
for j in range(9-i,0,-1):
print(' ',end=' ')
for k in range(1,i+1):
print(k,end=' ')
print()
'''
1
12
123
1234
12345
123456
1234567
12345678
123456789
'''
PATTERN-2
PATTERN-3
'''
Enter any value 10
$
$$
$$$
$$$$
$$$$$
$$$$$$
$$$$$$$
$$$$$$$$
$$$$$$$$$
''’
PATTERN-4
for i in range(1,10):
for j in range(9-i,0,-1):
print(j ,end=' ')
print()
'''
87654321
7654321
654321
54321
4321
321
21
1
'''
PATTERN-5
CONVERT THE NUMBER ENTERED BY THE USER INTO CORRESPONDING NUMBER IN WORDS
USING DICTIONARY
for j in val:
print(j,end="\t\t")
print()
print('='*80)
x=input('Enter the empno to be searched :/ ')
TUPLE-2
TUPLE-3
n=int(input("n="))
efinal=()
dfinal=()
complete=()
for i in range(n):
email=input("Enter the email id: ")
complete=complete+(email,)
em,dm=email.split('@')
efinal+=(em,)
dfinal+=(dm,)
print("Email id= ", efinal)
print("Domain Name= ",dfinal)
print("Complete= ", complete)
'''
n=3
Enter the email id: [email protected]
Enter the email id: [email protected]
Enter the email id: [email protected]
Email id= ('stef', 'kiki', 'tush')
Domain Name= ('bonzo.com', 'tamix.com', 'kammo.com')
Complete= ('[email protected]', '[email protected]', '[email protected]')
'''
TUPLE-4
a=input("Enter a string: ")
b=tuple(a)
print("Tuple created from string: ",b)
'''
Enter a string: Tamanna
Tuple created from string: ('T', 'a', 'm', 'a', 'n', 'n', 'a')
'''
TUPLE-5
a=eval(input("Enter a tuple: "))
s=0
for i in a:
if i%2==0:
s+=i
print(s)
'''
Enter a tuple: (1,2,3,4,5,6,7,8)
20
'''
BASIC OPERATORS
WAP to read the Marks of 5 subjects from the user and print the Total Marks and
Percentage .