0% found this document useful (0 votes)
26 views6 pages

Class 11 CS Practical File

The document outlines several Python programs with specific aims, algorithms, and source codes. It includes programs for inputting and displaying messages, finding the largest and smallest numbers, generating patterns, determining Armstrong numbers, and checking if a number is prime or composite. Each program is followed by a confirmation of successful execution and verification.

Uploaded by

xopabe3097
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

Class 11 CS Practical File

The document outlines several Python programs with specific aims, algorithms, and source codes. It includes programs for inputting and displaying messages, finding the largest and smallest numbers, generating patterns, determining Armstrong numbers, and checking if a number is prime or composite. Each program is followed by a confirmation of successful execution and verification.

Uploaded by

xopabe3097
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Input a welcome message and display it.

Aim:

Write a python program to input a welcome message and print it

Algorithm:

Step 1:- Start

Step 2:- Read input from the user

Step 3:- Assign the input in same varaiable

Step 4:- Show message

Step 5:-Stop

Source Code:-

message=input("Enter welcome message : ")


print("Hello, ",message)

Result:-

Thus, the given program has been executed and verified successfully.

Output
Input two numbers and display the larger number

Aim:

To write a python program to find the largest of two numbers.

Algorithm:

Step 1:- Start

Step 2:- Input two numbers,a and b

Step 3:- Check if a is greater than b. If true,print a. Otherwise print b.

Step 4:- Stop

Source Code:-

a=int(input("Enter First Number"))

b=int(input("Enter Second Number"))

if (a>b):

print("The Larger number is", a)

else:

print ("The Larger number is", b)

Result:-

Thus, the given program has been executed and verified successfully.

Output
Input three numbers and display the smallest number

Aim:

To write a python program to find the largest of three numbers.

Algorithm:

Step 1: Start

Step 2: Read three numbers in variable a, b and c.

Step 3:

If a<b and a<c then display “a is the smallest number"

If b<a and b<c then display “b is the smallest number"

If c<a and c<b then display “c is the smallest number"

Step 4: Stop

Source Code:-

a=int(input("Enter First Number="))

b=int(input("Enter Second Number="))

c=int(input("Enter Third Number="))

if (a< b and a< c):

print("The Smallest number is=", a )

elif (b < a and b < c):

print ("The Smallest number is=", b)

else:

print ("The smallest number is=", c)

Result:-

Thus, the given program has been executed and verified successfully.

Output
Generate the following patterns using nested loop

Aim:

To write a python program to Generate the following patterns using nested loop.

Algorithm:

Step 1: Start

Step 2: Repeat step 3 to 5 until all value parse.

Step 3: Set i = 1 and check i<6;

Step 4: Set j = 1 and check j <i+1;

Step 5: Print "*".

Step 6: Stop

Source Code:-

for i in range(1,6):

for j in range(1,i+1):

print("*",end=" ")

print()

Result:-

Thus, the given program has been executed and verified successfully.

Output
Determine whether a number is an Armstrong number

Aim:

To write a python program to determine whether a number is an Armstrong number or


not

Algorithm:

Step 1: Read number

Step 2: Declare a variable sum and initialize it to 0

Step 2: for each digit in the number, multiply it thrice and add it to the sum.

Step 3: check the sum if it is equal to the initial number

Step 4: If both are equal, then print it as an Armstrong number. Else, print it as not an
Armstrong number.

Source Code:

number = 153

digits = len(str(number))

temp = number

sum = 0

while temp != 0:

k = temp % 10

sum += k**digits

temp = temp//10

if sum == number:

print('Given number is an Armstrong Number')

else:

print('Given number is not an Armstrong Number')

Result:-

Thus, the given program has been executed and verified successfully.

Output
Input a number and check if the number is a prime or composite number

Aim:-

To write a python program to input a number and check if the number is a prime or
composite number

Algorithm :-

Step 1: Start
Step 2: Read input number using input()
Step 3: Check if num is greater than 1.
Step 4: Find factors

 Run a for loop ranging from 2 to the num entered.


 check if num divided by any number gives a remainder 0.
 if it gives a remainder of 0, the number is not a prime number.
 if not, the number is a prime number.
Step 5: If the number entered is either 0 or 1, we say that the number is neither prime nor
composite number.
Step 7: All other numbers are composite numbers.
Step 8:Print the result.
Step 9:Stop

Source Code:

num = int(input("Enter any number : "))


if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, "is NOT a prime number")
break
else:
print(num, "is a PRIME number")
elif num == 0 or 1:
print(num, "is a neither prime NOR composite number")
else:
print(num, "is NOT a prime number it is a COMPOSITE number")
Result:-

Thus, the given program has been executed and verified successfully.

Output

You might also like