0% found this document useful (0 votes)
2 views

CS Holiday Homework

Cs important

Uploaded by

Siddharth Rana
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)
2 views

CS Holiday Homework

Cs important

Uploaded by

Siddharth Rana
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/ 8

HOLIDAY

HOMEWORK
COMPUTER
PRACTICAL
FILE

BY: -
SIDDHARTH RANA
TH
11 SCI
Program 1: Hello world
Code
print("Hello, World!")

Output:

Program 2: Sum of two numbers


Code
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
sum = num1 + num2
print("The sum is:", sum)

Output:

Program 3 : Factorial of a number


Code
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print("The factorial of", num, "is:", factorial)

Output:

Program 4: Check prime number


Code
num = int(input("Enter a number: "))
is_prime = True
if num > 1:
for i in range(2, int(num / 2) + 1):
if num % i == 0:
is_prime = False
break
else:
is_prime = False
if is_prime:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

Output:
Program 5: Fibonacci Series
Code
num_terms = int(input("Enter the number of terms: "))
fibonacci_series = [0, 1]
if num_terms > 2:
for i in range(2, num_terms):
next_term = fibonacci_series[i - 1] + fibonacci_series[i - 2]
fibonacci_series.append(next_term)
print("The Fibonacci series is:", fibonacci_series)

Output:

Program 6 : String Reversal


Code
string = input("Enter a string: ")
reversed_string = string[::-1]
print("The reversed string is:", reversed_string)
Output:

Program 7: Sum of Digits in a Number


Code
num = int(input("Enter a number: "))
sum = 0
while num > 0:
digit = num % 10
sum += digit
num //= 10
print("The sum of digits is:", sum)

Output:

Program 8: Check Palindrome


Code
string = input("Enter a string: ")
is_palindrome = string == string[::-1]
if is_palindrome:
print("It is a palindrome")
else:
print("It is not a palindrome")
Output:

Program 9 : Swap Two Variables


Code
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
print("Before swapping: num1 =", num1, "num2 =", num2)
num1, num2 = num2, num1
print("After swapping: num1 =", num1, "num2 =", num2)

Output:

Program 10 : Find Maximum of Three Numbers


Code
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
max_num = max(num1, num2, num3)
print("The maximum number is:", max_num)

Output:

You might also like