cs practical
cs practical
1. WAP to enter a list and shift all the negative numbers to the left side and positive to the right
side and display the final list.
“””
def shift_numbers(L):
for i in L:
if i < 0:
L.remove(i)
L.insert(0,i)
shift_numbers(L)
def exchange(L):
n = len(L)//2
L = exchange(L)
def check_palindrome(n):
num = n
rev = 0
while n > 0:
rem = n%10
n //= 10
if num == rev:
else:
check_palindrome(n)
# 4. WAP to check whether the given number is Armstrong or not.
def check_armstrong(n):
num = n
no_of_digits = len(str(n))
Sum = 0
while n > 0:
digit = n % 10
n //= 10
if Sum == num:
else:
check_armstrong(n)
# 5. WAP to enter a string and count the total number of vowels and consonants present in it.
def count_vow_cons(s):
vow = cons = 0
for i in s:
if i.isalpha():
if i in 'AEIOUaeiou':
vow += 1
else:
cons += 1
count_vow_cons(s)
“””
6. WAF LShift(Arr,n) in Python which accepts list Arr if no.s and n is a numeric value by which all
the elements are shifted to the left.
“””
def LShift(Arr,n):
print(Arr)
LShift(L,n)
“””
7. WAP to enter a string to search a specific character and display the position if it is found
otherwise display an error message.
“””
def search(string,Chr):
for i in range(len(string)):
if string[i] == Chr:
return
search(string,Chr)
“””
8. WAP that takes a string with multiple words and capitalize the first letter of each word.(without
using title()
“””
def capitalise_first_letter(s):
L = split(s)
for i in range(len(L)):
s2 = capitalise_first_letter(s)
9. Consider a dictionary my_points with single-letter keys, each followed by a 2-element tuple
representing the coordinates of
my_points = {'a':(4,3),'b':(1,2),'c':(5,1)}
WAP to calculate the maximum value from within all of the values tuple at the same index.
"""
def ABC(my_points):
x=y=0
for i in my_points.values():
if i[0] > x:
x = i[0]
if i[1] > y:
y = i[1]
my_points = {'a':(4,3),'b':(1,2),'c':(5,1)}
ABC(my_points)
“””
10. WAF DISPLAY(R) in Python, which takes the dictionary, R as an argument and displays the
names in uppercase whose names begin with "R".
“””
def DISPLAY(R):
for key in R:
if key[0] == 'R':
print(key.upper())
DISPLAY(D)