0% found this document useful (0 votes)
11 views10 pages

cs practical

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)
11 views10 pages

cs practical

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/ 10

“””

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)

L = eval(input("Enter a list of numbers: "))

shift_numbers(L)

print("Final list is: ",L)


# 2. WAP to exchange the first half elements with the second half elements and display the list.

def exchange(L):

n = len(L)//2

return L[n:] + L[:n]

L = eval(input("Enter a list of numbers: "))

L = exchange(L)

print("Final list is: ",L)


# 3. WAP to check whether the given number is palindrome or not.

def check_palindrome(n):

num = n

rev = 0

while n > 0:

rem = n%10

rev = rev*10 + rem

n //= 10

if num == rev:

print("The no. is palindrome no.")

else:

print("The no. is not a palindrome no.")

n = int(input("Enter a number: "))

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

Sum += digit ** no_of_digits

n //= 10

if Sum == num:

print("The no. is armstrong no.")

else:

print("The no. is not armstrong no.")

n = int(input("Enter a number: "))

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

print("No. of vowels: ",vow)

print("No. of consonants: ",cons)

s = input("Enter a string: ")

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):

Arr = Arr[n:] + Arr[:n]

print(Arr)

L = eval(input("Enter a list of no.s : "))

n = int(input("Enter position: "))

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.

NOTE: Don't use find or index keywords

“””

def search(string,Chr):

for i in range(len(string)):

if string[i] == Chr:

print("The character ",Chr," is at position: ", i)

return

print("ERROR THE CHARACTER NOT FOUND")

string = input("Enter a string: ")

Chr = input("Enter a single character: ")

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)):

L[i] = L[i][0].upper() + L[i][1:]

return " ".join(L)

s = input("Enter multiple line string: ")

s2 = capitalise_first_letter(s)

print(s2," is the new string with capitalise 1st letter")


"""

9. Consider a dictionary my_points with single-letter keys, each followed by a 2-element tuple
representing the coordinates of

a point in an x-y plane.

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]

print("Maximum value at index(mypoints,0) = ",x)

print("Maximum value at index(mypoints,1) = ",y)

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())

D = eval(input("Eneter a dictionary: "))

DISPLAY(D)

You might also like