Cs Practical H
Cs Practical H
*
* *
* * *
* * * *
* * * * *
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
3) Alphabet staicase
num_steps = int(input("Enter the number of steps for the staircase:
"))
A
AB
ABC
ABCD
ABCDE
result = 0
for i in range(n + 1):
result += x ** i
5) 1-x+x^2-x^3…+x^n
result = 0
for i in range(n + 1):
result += ((-1) ** i) * (x ** i)
6) (x^2)/2 + (x^3)/3…+
(x^n)/n
x = float(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
result = 0
for i in range(1, n + 1):
result += (x ** i) / i
7) X + (x^2)/2! + (x^3)/3!…+
(x^n)/n!
import math
x = float(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
result = 0
for i in range(1, n + 1):
result += (x ** i) / math.factorial(i)
if str(num) == str(num)[::-1]:
print("The number is Palindrome.")
elif num == sum(int(digit) ** len(str(num)) for digit
in str(num)):
print("The number is Armstrong.")
else:
print("The number is Normal.")
ENTER A NUMBER: 242
THE NUMBER IS PALINDROME
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("The number is Composite.")
break
else:
print("The number is Prime.")
elif num == 1:
print("The number is neither Prime nor
Composite.")
else:
print("Invalid input. Please enter a positive
integer greater than 1.")
ENTER A NUMBER: 4
THE NUMBER IS COMPOSITE.
9) Print fibonacci series
print("Fibonacci Series:")
for term in fibonacci_series:
print(term, end=" ")
lowercase_count = 0
uppercase_count = 0
vowel_count = 0
consonant_count = 0
vowels = set("aeiouAEIOU")
if cleaned_string == cleaned_string[::-1]:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
if len(numbers) % 2 == 0:
for i in range(0, len(numbers), 2):
numbers[i], numbers[i + 1] = numbers[i + 1],
numbers[i]
MODIFIED LIST: [3 , 2, 5, 4, 7, 6, 9, 8]
students_dict = {}
for _ in range(num_students):
roll_number = input("Enter Roll Number: ")
name = input("Enter Name: ")
marks = float(input("Enter Marks: "))
students_dict[roll_number] = {'Name': name,
'Marks': marks}
max_marks = 100.0
cutoff_percentage = 75.0
cutoff_marks = (cutoff_percentage / 100) * max_marks