Wednesday, 14 February 2024

Class 11 CS Practical - 33

 

33 - Write a program in Python to Input a list of numbers and find the largest number in a list. 


L=[]

c='y'

while c=='y' or c=='Y':

    a=int(input("Enter an integer number to append in the list: "))

    L.append(a)

    c=input("Do you want to add more elements in the list (Y/N): ")

print("List is: \n", L)

print("Maximum(Largest) number of the list = ",max(L))


Output:

Enter an integer number to append in the list: 5

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 8

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 2

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 9

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 4

Do you want to add more elements in the list (Y/N): n

List is: 

 [5, 8, 2, 9, 4]

Maximum(Largest) number of the list =  9

Class 11 CS Practical - 32

 

32 - Write a program in Python to input a string and convert the case of characters (uppercase to lowercase and lowercase to uppercase) in the string. 


S=input("Enter a string: ")

NS=''

for i in range(0,len(S)):

    if S[i].isupper():

        NS+=S[i].lower()

    elif S[i].islower():

        NS+=S[i].upper()

    else:

        NS+=S[i]

print("New String = ",NS)


Output:

Enter a string: Python @ PrograMMing

New String =  pYTHON @ pROGRAmmING



Class 11 CS Practical - 31

 

31 - Write a program in Python to input a string, then Count and display the number of vowels, consonants, uppercase, lowercase characters in string.


S=input("Enter a string: ")

v=0

c=0

u=0

l=0

print("Total number of characters in the string = ", len(S))

for i in S:

    if i in 'aeiouAEIOU':

        v=v+1

    elif i>='a' and i<='z':

        c=c+1

    elif i>='A' and i<='Z':

        c=c+1

print("Number of Vowels = ", v)

print("Number of consonants = ", c)

for i in S:

    if i.isupper():

        u=u+1

    elif i.islower():

        l=l+1

print("Number of uppercase letters = ", u)

print("Number of lowercase letters = ", l)


Output:

Enter a string: This is a Python Program

Total number of characters in the string =  24

Number of Vowels =  6

Number of consonants =  14

Number of uppercase letters =  3

Number of lowercase letters =  17



Enter a string: S@chin P@r@sh@r

Total number of characters in the string =  15

Number of Vowels =  1

Number of consonants =  9

Number of uppercase letters =  2

Number of lowercase letters =  8



Tuesday, 13 February 2024

Class 11 CS Practical - 30

 

30 - Write a program in Python to input a string and determine whether the string a palindrome or not.

S=input("Enter a string: ")

if S ==  S[::-1]:

    print("String is Palindrome")

else:

    print("String is not Palindrome")



Class 11 CS Practical - 29

 

29 - Write a program in Python to computer the least common multiple of two integers.

import math

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

b=int(input("Enter second number: ")) 

print("LCM of ",a,"and",b,"=",math.lcm(a,b))



Output:

Enter first number: 5
Enter second number: 7
LCM of  5 and 7 = 35

Enter first number: 8
Enter second number: 12
LCM of  8 and 12 = 24


Class 11 CS Practical - 28

 

28 - Write a program in Python to compute the greatest common divisor of two integers.

import math

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

b=int(input("Enter second number: ")) 

print("GCD/HCF of ",a,"and",b,"=",math.gcd(a,b))


Output:

Enter first number: 60

Enter second number: 48

GCD/HCF of  60 and 48 = 12


Enter first number: 24

Enter second number: 18

GCD/HCF of  24 and 18 = 6




Class 11 CS Practical - 27

 

27 - Write a program in Python to input a number and determine whether the number is composite number or not.


Composite Numbers 

Composite Numbers are numbers that have more than two factors. These numbers are also called composites. Composite numbers are just the opposite of prime numbers which have only two factors, i.e. 1 and the number itself. All the natural numbers which are not prime numbers are composite numbers as they can be divided by more than two numbers. For example, 6 is a composite number because it is divisible by 1, 2, 3 and 6.

Examples:

4, 6, 8, 9, 10 etc.


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

for i in range(2,n+1): 

    if (n%i==0): 

        break 

if(n==i): 

    print(n,"is not a composite number") 

else: 

    print(n,"is a composite number")  


Output:

Enter the number: 4

4 is a composite number

Enter the number: 5

5 is not a composite number

Enter the number: 9

9 is a composite number



Class 11 CS Practical - 26

 

26 - Write a program in Python to to generate all prime numbers between 2 to 100.

print("Prime Number from 2 to 100: ")

for n in range(2,101):

    for i in range(2,n+1): 

        if (n%i==0): 

            break 

    if(n==i): 

        print(n,end=" ") 


Output:

Prime Number from 2 to 100:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97


Class 11 CS Practical - 25

 

25 - Write a program in Python to input a number and determine whether the number is a prime number or not.

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

for i in range(2,n+1): 

    if (n%i==0): 

        break 

if(n==i): 

    print(n,"is a prime number") 

else: 

    print(n,"is not a prime number") 


Output:


Enter the number: 29

29 is a prime number

Enter the number: 37

37 is a prime number

Enter the number: 35

35 is not a prime number


Class 11 CS Practical - 24


24 - Write a program in Python to input a number and determine whether the number is a perfect number or not.

Perfect Number

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.

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

sum=0 

for i in range(1,n): 

    if (n%i==0): 

        sum = sum+i 

if(sum==n): 

    print(n,"is a perfect number") 

else: 

    print(n,"is not a perfect number")


Output:

Enter the number: 6

6  is a perfect number

Enter the number: 25

25  is not a perfect number