0% found this document useful (0 votes)
56 views70 pages

Cs File

Uploaded by

vehiy77625
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)
56 views70 pages

Cs File

Uploaded by

vehiy77625
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
You are on page 1/ 70

Python Code: Program_1_1.

py

# Adhiraj Dhawan S6-C


# TASK 01: WAPP to display Hello World! on the screen.
print("Hello World!")

Output: Hello World!


Output:
Python Code: Program_1_10.py

# Adhiraj Dhawan S6-C


# TASK 10: WAPP to demonstrate all methods available in the math module.
import math

# Display values of mathematical constants


print("Value of pi:", math.pi)
print("Value of e:", math.e)

# Trigonometric functions
angle = math.radians(45)
print("Sine of 45 degrees:", math.sin(angle))
print("Cosine of 45 degrees:", math.cos(angle))
print("Tangent of 45 degrees:", math.tan(angle))

# Logarithmic functions
print("Logarithm of 2 to the base 10:", math.log10(2))
print("Natural logarithm of 2:", math.log(2))

# Other functions
print("Square root of 25:", math.sqrt(25))
print("Factorial of 5:", math.factorial(5))

Output: Value of pi: 3.141592653589793


Output: Value of e: 2.718281828459045
Output: Sine of 45 degrees: 0.7071067811865476
Output: Cosine of 45 degrees: 0.7071067811865476
Output: Tangent of 45 degrees: 0.9999999999999999
Output: Logarithm of 2 to the base 10: 0.3010299956639812
Output: Natural logarithm of 2: 0.6931471805599453
Output: Square root of 25: 5.0
Output: Factorial of 5: 120
Output:
Python Code: Program_1_11.py

# Adhiraj Dhawan S6-C

# TASK 11: WAPP to demonstrate all methods available in random module.


import random

def random_module_demo():
print('Random Integer:', random.randint(1, 100))
print('Random Float:', random.random())
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)
print('Shuffled List:', numbers)
print('Random Choice:', random.choice(numbers))

random_module_demo()

Output: Random Integer: 53


Output: Random Float: 0.660431507652266
Output: Shuffled List: [1, 5, 3, 2, 4]
Output: Random Choice: 1
Output:
Python Code: Program_1_12.py

# Adhiraj Dhawan S6-C

# TASK 12: WAPP to input annual income of a person and calculate the payable income tax based
income = int(input('Enter annual income: '))
if income <= 250000:
tax = 0
elif 250000 < income <= 500000:
tax = 0.05 * (income - 250000)
elif 500000 < income <= 1000000:
tax = 0.05 * (500000 - 250000) + 0.1 * (income - 500000)
else:
tax = 0.05 * (500000 - 250000) + 0.1 * (1000000 - 500000) + 0.2 * (income - 1000000)
print('Payable Income Tax:',tax)

Output: Enter annual income:


Python Code: Program_1_13.py

# Adhiraj Dhawan S6-C

# TASK 13: WAPP to input eclectic consumption (present reading – previous reading) of a house
f=int(input("Enter the Number of bills you want to calculate:"))
while f>0:
f=f-1
n=int(input("input present reading:"))
k=int(input("input previous reading:"))
b=(n-k)
a=0
c=0
if b<0:
print("ERROR please check the units entered no of units entered are",b)
elif b<=200:
print ("bill is 0")
elif b>200 and b<=400:
c=b-200
print ("Your bill amount is:",600+ (c*4.5))
elif b>400 and b<=800:
c=b-600
print ("Your bill amount is:",600+900+(c*6.5))
elif b>800 and b<=1200:
c=b-800
print ("Your bill amount is:",600+900+2600+ (c*7))
else:
c=b-1200
print ("Your bill amount is:",600+900+2600+ (c*7.75))

Output: Enter the Number of bills you want to calculate:input present reading:
Python Code: Program_1_14.py

# Adhiraj Dhawan S6-C

# TASK 14: WAPP to input two natural numbers and display all the EVEN numbers between those.
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
for num in range(num1, num2 + 1):
if num % 2 == 0:
print(num)

Output: Enter the first number:


Python Code: Program_1_15.py

# Adhiraj Dhawan S6-C

# TASK 15: WAPP to input a natural number and display the MULTIPLICATION TABLE of that
n = int(input('Enter a number: '))
for i in range(1, 11):
print(n * i)

Output: Enter a number:


Python Code: Program_1_16.py

# Adhiraj Dhawan S6-C

# TASK 16: WAPP to input a natural number N and display first N FIBONACCI numbers.
term = int(input('Enter the number of terms: '))
a, b = 0, 1
for _ in range(term):
print(a, end=' ')
a, b = b, a + b

Output: Enter the number of terms:


Python Code: Program_1_17.py

# Adhiraj Dhawan S6-C


# TASK 17: WAPP to input a natural number and display all the FACTORS of that number.
number = int(input('Enter a number: '))
for i in range(1, number + 1):
if number % i == 0:
print(i)

Output: Enter a number:


Python Code: Program_1_18.py

# Adhiraj Dhawan S6-C

# TASK 18: WAPP to input a natural number and display the SUM OF all its proper FACTORS.
number = int(input('Enter a number: '))
total = 0
for i in range(1, number):
if number % i == 0:
total += i
print('Sum of Factors:', total)

Output: Enter a number: Sum of Factors: 1


Output:
Python Code: Program_1_19.py

# Adhiraj Dhawan S6-C

# TASK 19: WAPP to input a natural number and check whether the number is a PERFECT or not.
number = int(input('Enter a number: '))
total=0
for i in range(1, number):
if number % i == 0:
total += i
if number==total:
print("It Is a perfect no")
else:
print("IT IS NOT")

Output: Enter a number: IT IS NOT


Output:
Python Code: Program_1_2.py

# Adhiraj Dhawan S6-C


# TASK 02: WAPP to demonstrate concatenation and repetition of strings.
string1 = "Hello"
string2 = "World"
concatenated_string = string1 + " " + string2
repeated_string = string1 * 3 # Repeat string1 three times
print("Concatenated String:", concatenated_string)
print("Repeated String:", repeated_string)

Output: Concatenated String: Hello World


Output: Repeated String: HelloHelloHello
Output:
Python Code: Program_1_20.py

# Adhiraj Dhawan S6-C

# TASK 20: WAPP to input two natural numbers and check whether those numbers are AMICABLE
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
total1=0
total2=0
for i in range(1, num1):
if num1 % i == 0:
total1 += i
for i in range(1, num2):
if num2 % i == 0:
total2 += i
if total1 == num2 and total2 == num1:
print("nos are amicable")
else:
print("they are not amicable")

Output: Enter the first number:


Python Code: Program_1_21.py

# Adhiraj Dhawan S6-C

# TASK 21: WAPP to input a natural number and check whether the number is a PRIME or not.
num = int(input('Enter a number: '))
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime and num > 1:
print('Prime')
else:
print('Not Prime')

Output: Enter a number: Not Prime


Output:
Python Code: Program_1_22.py

# Adhiraj Dhawan S6-C

# TASK 22: WAPP to input a natural number N and display the first N PRIME numbers.
N = int(input('Enter the value of N: '))
count = 0
num = 2
while count < N:
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=' ')
count += 1
num += 1

Output: Enter the value of N: 2 3 5 7 11


Python Code: Program_1_23.py

# Adhiraj Dhawan S6-C

# TASK 23: WAPP to input a number N and display all PRIME numbers less than equals to N.
N = int(input('Enter the value of N: '))
for num in range(2, N + 1):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=' ')

Output: Enter the value of N: 2 3 5 7 11 13 17 19 23 29 31 37 41 43


Python Code: Program_1_24.py

# Adhiraj Dhawan S6-C

# TASK 24: WAPP to input a natural number N and display the sum of all PRIME numbers less than equals
N = int(input('Enter the value of N: '))
prime_sum = 0
for num in range(2, N + 1):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
prime_sum += num
print('Sum of Prime Numbers:', prime_sum)

Output: Enter the value of N:


Python Code: Program_1_25.py

# Adhiraj Dhawan S6-C

# TASK 25: WAPP to input two natural numbers and calculate and display their HCF/GCD
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
while num2:
num1, num2 = num2, num1 % num2
print('HCF/GCD:', num1)

Output: Enter the first number:


Python Code: Program_1_26.py

# Adhiraj Dhawan S6-C

# TASK 26: WAPP to input two natural numbers and check whether they are CO-PRIME or not.
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
hcf = 0
for i in range(1, min(num1, num2) + 1):
if num1 % i == 0 and num2 % i == 0:
hcf = i
if hcf == 1:
print('Co-Prime')
else:
print('Not Co-Prime')

Output: Enter the first number:


Python Code: Program_1_27.py

# Adhiraj Dhawan S6-C

# TASK 27: WAPP to input two natural numbers and calculate and display their LCM
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
hcf = 0
for i in range(1, min(num1, num2) + 1):
if num1 % i == 0 and num2 % i == 0:
hcf = i
lcm = (num1 * num2) // hcf
print('LCM:', lcm)

Output: Enter the first number: Enter the second number:


Python Code: Program_1_28.py

# Adhiraj Dhawan S6-C

# TASK 28: WAPP to input a natural number and display the SUM OF all its DIGITS.
number = int(input('Enter a number: '))
digit_sum = sum(map(int, str(number)))
print('Sum of Digits:', digit_sum)

Output: Enter a number:


Python Code: Program_1_29.py

# Adhiraj Dhawan S6-C

# TASK 29: WAPP to input a natural number and check whether the number is a ARMSTRONG number or not.
number = int(input('Enter a number: '))
order = len(str(number))
armstrong_sum = sum(int(digit) ** order for digit in str(number))
if armstrong_sum == number:
print('Armstrong Number')
else:
print('Not Armstrong Number')

Output: Enter a number:


Python Code: Program_1_3.py

# Adhiraj Dhawan S6-C


# TASK 03: WAPP to demonstrate floor division and modulus operators.
num1 = 17
num2 = 5
floor_result = num1 // num2
modulus_result = num1 % num2
print("Floor Division Result:", floor_result)
print("Modulus Result:", modulus_result)

Output: Floor Division Result: 3


Output: Modulus Result: 2
Output:
Python Code: Program_1_30.py

# Adhiraj Dhawan S6-C

# TASK 30: WAPP to input a natural numbers and display the same but after REVERSING its digits.
number = int(input('Enter a number: '))
reverse_number = int(str(number)[::-1])
print('Original Number:', number)
print('Reversed Number:', reverse_number)

Output: Enter a number: Original Number: 65


Output: Reversed Number: 56
Output:
Python Code: Program_1_31.py

# Adhiraj Dhawan S6-C

# TASK 31: WAPP to input a natural numbers and check whether the number is PALINDROMIC or not.
number = input('Enter a number: ')
if number == number[::-1]:
print('PALINDROMIC')
else:
print('NOT PALINDROMIC')

Output: Enter a number: NOT PALINDROMIC


Output:
Python Code: Program_1_32.py

# Adhiraj Dhawan S6-C

# TASK 32: WAPP to input an amount of money and display MINIMUM CURRENCY NOTES (out of 2000/500/200/1
amount = int(input('Enter the amount: '))
notes = [2000, 500, 200, 100, 50, 20, 10, 5, 2, 1]
for note in notes:
count = amount // note
if count > 0:
print(f'{count} x {note} notes')
amount %= note

Output: Enter the amount:


Python Code: Program_1_33.py

# Adhiraj Dhawan S6-C

# TASK 33: WAPP to input a natural numbers and check whether the number is PALINDROMIC or not.
number = input('Enter a number: ')
if number == number[::-1]:
print('PALINDROMIC')
else:
print('NOT PALINDROMIC')

Output: Enter a number: NOT PALINDROMIC


Output:
Python Code: Program_1_34.py

# Adhiraj Dhawan S6-C

# TASK 34: WAPP to read a sentence and display the number of occurrences of each characters.
sentence = input('Enter a sentence: ')
character_count = {}
for char in sentence:
character_count[char] = character_count.get(char, 0) + 1
for char, count in character_count.items():
print(f'{char}: {count} times')

Output: Enter a sentence: 8: 1 times


Output: 2: 1 times
Output:
Python Code: Program_1_35.py

# Adhiraj Dhawan S6-C

# TASK 35: WAPP to read a sentence and display the number of occurrences of each words.
sentence = input('Enter a sentence: ')
word_count = {}
words = sentence.split()
for word in words:
word_count[word] = word_count.get(word, 0) + 1
for word, count in word_count.items():
print(f'{word}: {count} times')

Output: Enter a sentence: pBJaLkk: 1 times


Output:
Python Code: Program_1_36.py

# Adhiraj Dhawan S6-C

# TASK 36: WAPP to input a natural numbers and display the same but after REVERSING its digits.
number = input('Enter a number: ')
reversed_number = int(number[::-1])
print('Reversed Number:', reversed_number)

Output: Enter a number:


Python Code: Program_1_37.py

# Adhiraj Dhawan S6-C

# TASK 37-A: WAPP to read a sentence and display the same by reversing characters of all words withou
sentence = input('Enter a sentence: ')
reversed_sentence = ' '.join(word[::-1] for word in sentence.split())
print('Reversed Sentence:', reversed_sentence)

Output: Enter a sentence: Reversed Sentence: 41


Output:
Python Code: Program_1_38.py

# Adhiraj Dhawan S6-C

# TASK 38-A: WAPP to read 3 numbers and display those in ASCENDING/DESCENDING order.
numbers = [int(input('Enter first number: ')), int(input('Enter second number: ')), int(input('Enter
print('Ascending Order:', sorted(numbers))
print('Descending Order:', sorted(numbers, reverse=True))

Output: Enter first number: Enter second number:


Python Code: Program_1_39.py

# Adhiraj Dhawan S6-C

# TASK 39: WAPP to input a natural number N and calculate & display the FACTORIAL of N.
n = int(input('Enter a natural number: '))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print('Factorial of', n, 'is:', factorial)

Output: Enter a natural number: Factorial of 43 is: 6041526306337383563735513206851399750726451200000


Output:
Python Code: Program_1_4.py

# Adhiraj Dhawan S6-C


# TASK 04: WAPP to read the age of a person and check whether the person can vote or not.
age = int(input("Enter the age: "))
if age >= 18:
print("Person can vote.")
else:
print("Person cannot vote.")

Output: Enter the age:


Python Code: Program_1_40.py

# Adhiraj Dhawan S6-C

# TASK 40: WAPP to illustrate the difference between append() vs insert() methods and pop() vs remove
my_list = [1, 2, 3, 4, 5]
print('Original List:', my_list)
# Append vs Insert
my_list.append(6)
print('List after append(6):', my_list)
my_list.insert(2, 7)
print('List after insert(2, 7):', my_list)
# Pop vs Remove
my_list.pop(3)
print('List after pop(3):', my_list)
my_list.remove(7)
print('List after remove(7):', my_list)

Output: Original List: [1, 2, 3, 4, 5]


Output: List after append(6): [1, 2, 3, 4, 5, 6]
Output: List after insert(2, 7): [1, 2, 7, 3, 4, 5, 6]
Output: List after pop(3): [1, 2, 7, 4, 5, 6]
Output: List after remove(7): [1, 2, 4, 5, 6]
Output:
Python Code: Program_1_41.py

# Program for Task 41

# Append vs Insert

my_list = [1, 2, 3]

# Using append
my_list.append(4)

# Using insert
my_list.insert(1, 5)

print("List after append and insert:", my_list)

Output: List after append and insert: [1, 5, 2, 3, 4]


Output:
Python Code: Program_1_42.py

# Program for Task 42

# Menu-based Operations on a List

my_numbers = []

while True:
print("1. Add Number")
print("2. Display Numbers")
print("3. Search Number")
print("4. Modify Number")
print("5. Delete Number")
print("6. Exit")

choice = int(input("Enter your choice: "))

if choice == 1:
number = int(input("Enter a number: "))
my_numbers.append(number)
elif choice == 2:
print("Numbers:", my_numbers)
elif choice == 3:
search_num = int(input("Enter number to search: "))
print("Found" if search_num in my_numbers else "Not Found")
elif choice == 4:
old_num = int(input("Enter number to modify: "))
new_num = int(input("Enter new number: "))
if old_num in my_numbers:
index = my_numbers.index(old_num)
my_numbers[index] = new_num
else:
print("Number not found")
elif choice == 5:
del_num = int(input("Enter number to delete: "))
if del_num in my_numbers:
my_numbers.remove(del_num)
else:
print("Number not found")
elif choice == 6:
break

Output: 1. Add Number


Output: 2. Display Numbers
Output: 3. Search Number
Output: 4. Modify Number
Output: 5. Delete Number
Output: 6. Exit
Output: Enter your choice:
Python Code: Program_1_43.py

# Program for Task 43

# List of Numbers and Statistics

import statistics

numbers = [10, 20, 30, 40, 50]

mean = statistics.mean(numbers)
median = statistics.median(numbers)
mode = statistics.mode(numbers)

print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)

Output: Mean: 30
Output: Median: 30
Output: Mode: 10
Output:
Python Code: Program_1_44.py

# Program for Task 44

# Stack Operations on a List of Numbers

stack = []

# Push (Add to stack)


stack.append(10)
stack.append(20)
stack.append(30)

# Pop (Remove from stack)


popped_item = stack.pop()

print("Stack after push and pop:", stack)


print("Popped item:", popped_item)

Output: Stack after push and pop: [10, 20]


Output: Popped item: 30
Output:
Python Code: Program_1_45.py

# Program for Task 45

# Separate List of Even and Odd Numbers

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

even_numbers = [num for num in numbers if num % 2 == 0]


odd_numbers = [num for num in numbers if num % 2 != 0]

print("Even numbers:", even_numbers)


print("Odd numbers:", odd_numbers)

Output: Even numbers: [2, 4, 6, 8, 10]


Output: Odd numbers: [1, 3, 5, 7, 9]
Output:
Python Code: Program_1_46.py

# Program for Task 46

# Display Pattern for String 'INDIA'

word = "INDIA"

for i in range(1, len(word)+1):


print(word[:i])

Output: I
Output: IN
Output: IND
Output: INDI
Output: INDIA
Output:
Python Code: Program_1_47.py

# Program for Task 47

# Display Initials as M.K.G

name = "John Doe"

# Extracting initials
initials = [char.upper() + "." for char in name.split()]

print("Initials:", "".join(initials))

Output: Initials: JOHN.DOE.


Output:
Python Code: Program_1_48.py

# Program for Task 48

# Display Initials as M.K.Gandhi

name = "Mahatma Gandhi"

# Extracting initials
initials = [char.upper() + "." for char in name.split()]

print("Initials:", "".join(initials))

Output: Initials: MAHATMA.GANDHI.


Output:
Python Code: Program_1_49.py

# Program for Task 49

# Check if a String is a Palindrome

def is_palindrome(s):
s = s.lower().replace(" ", "")
return s == s[::-1]

string_to_check = "level"

if is_palindrome(string_to_check):
print(f"{string_to_check} is a palindrome.")
else:
print(f"{string_to_check} is not a palindrome.")

Output: level is a palindrome.


Output:
Python Code: Program_1_5.py

# Adhiraj Dhawan S6-C


# TASK 05: WAPP to calculate the area of different geometrical figures based on Usprint("Choose a geo
print("1. Square")
print("2. Rectangle")
print("3. Circle")
choice = int(input("Enter your choice (1/2/3): "))

if choice == 1:
side = float(input("Enter the side length of the square: "))
area = side ** 2
print("Area of the square:", area)
elif choice == 2:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print("Area of the rectangle:", area)
elif choice == 3:
radius = float(input("Enter the radius of the circle: "))
area = 3.14 * (radius ** 2)
print("Area of the circle:", area)
else:
print("Invalid choice. Please choose 1, 2, or 3.")

Output: 1. Square
Output: 2. Rectangle
Output: 3. Circle
Output: Enter your choice (1/2/3): Invalid choice. Please choose 1, 2, or 3.
Output:
Python Code: Program_1_50.py

# Program for Task 50

# Reverse Characters of Words in a Sentence

sentence = "Hello World"

reversed_sentence = " ".join(word[::-1] for word in sentence.split())

print("Reversed Sentence:", reversed_sentence)

Output: Reversed Sentence: olleH dlroW


Output:
Python Code: Program_1_51.py

# Program for Task 51

# Check if Sentence Contains a Specific Word

sentence = "This is a sample sentence."

word_to_check = input("Enter a word to check: ")

if word_to_check in sentence:
print(f"The sentence contains the word '{word_to_check}'.")
else:
print(f"The sentence does not contain the word '{word_to_check}'.")

Output: Enter a word to check: The sentence does not contain the word 'RlHqMj'.
Output:
Python Code: Program_1_52.py

# Program for Task 52

# Display Country Names with 6 or More Characters

countries = ["India", "USA", "Canada", "Brazil", "China", "Germany", "France", "Australia", "Japan",

long_countries = [country for country in countries if len(country) >= 6]

print("Countries with 6 or more characters:", long_countries)

Output: Countries with 6 or more characters: ['Canada', 'Brazil', 'Germany', 'France', 'Australia']
Output:
Python Code: Program_1_53.py

# Program for Task 53

# Display Names Starting with Vowels

names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Henry", "Ivy", "Jack"]

vowel_starting_names = [name for name in names if name[0].lower() in ['a', 'e', 'i', 'o', 'u']]

print("Names starting with vowels:", vowel_starting_names)

Output: Names starting with vowels: ['Alice', 'Eva', 'Ivy']


Output:
Python Code: Program_1_54.py

# Program for Task 54

# Display Names Ending with Consonants

names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Henry", "Ivy", "Jack"]

consonant_ending_names = [name for name in names if name[-1].lower() not in ['a', 'e', 'i', 'o', 'u']

print("Names ending with consonants:", consonant_ending_names)

Output: Names ending with consonants: ['Bob', 'David', 'Frank', 'Henry', 'Ivy', 'Jack']
Output:
Python Code: Program_1_55.py

# Program for Task 55

# Queue (FIFO) Operations on a List of Names

queue = []

# Enqueue (Add to the queue)


queue.append("Alice")
queue.append("Bob")
queue.append("Charlie")

# Dequeue (Remove from the queue)


dequeued_item = queue.pop(0)

print("Queue after enqueue and dequeue:", queue)


print("Dequeued item:", dequeued_item)

Output: Queue after enqueue and dequeue: ['Bob', 'Charlie']


Output: Dequeued item: Alice
Output:
Python Code: Program_1_56.py

# Program for Task 56

# Stack (LIFO) Operations on a Tuple of Numbers

my_tuple = (1, 2, 3)

# Push (Add to stack)


stack = my_tuple + (4,)

# Pop (Remove from stack)


popped_item = stack[-1]

print("Stack after push and pop:", stack)


print("Popped item:", popped_item)

Output: Stack after push and pop: (1, 2, 3, 4)


Output: Popped item: 4
Output:
Python Code: Program_1_57.py

# Program for Task 57

# Stack (LIFO) Operations on a List of Tuples of Student Details

students = [
("Alice", 90),
("Bob", 85),
("Charlie", 92)
]

# Push (Add to stack)


students.append(("David", 88))

# Pop (Remove from stack)


removed_student = students.pop()

print("Students after push and pop:", students)


print("Removed student:", removed_student)

Output: Students after push and pop: [('Alice', 90), ('Bob', 85), ('Charlie', 92)]
Output: Removed student: ('David', 88)
Output:
Python Code: Program_1_58.py

# Program for Task 58

# Demonstrate Tuple Functions

my_tuple = (10, 20, 30, 40, 50)

# Tuple length
length = len(my_tuple)

# Tuple sum
total = sum(my_tuple)

# Tuple maximum
maximum = max(my_tuple)

# Tuple minimum
minimum = min(my_tuple)

print("Length:", length)
print("Sum:", total)
print("Maximum:", maximum)
print("Minimum:", minimum)

Output: Length: 5
Output: Sum: 150
Output: Maximum: 50
Output: Minimum: 10
Output:
Python Code: Program_1_59.py

# Program for Task 59

# Demonstrate Dictionary Functions

my_dict = {
"Alice": 90,
"Bob": 85,
"Charlie": 92
}

# Adding a new entry


my_dict["David"] = 88

# Display keys and values


keys = list(my_dict.keys())
values = list(my_dict.values())

print("Keys:", keys)
print("Values:", values)

Output: Keys: ['Alice', 'Bob', 'Charlie', 'David']


Output: Values: [90, 85, 92, 88]
Output:
Python Code: Program_1_6.py

# Adhiraj Dhawan S6-C


# TASK 06: WAPP to solve a quadratic equation and also display the nature of roots.
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))

# Calculate the discriminant


discriminant = (b**2) - (4*a*c)

# Calculate the roots


root1 = (-b - discriminant**0.5) / (2*a)
root2 = (-b + discriminant**0.5) / (2*a)

print("Root 1:", root1)


print("Root 2:", root2)

# Determine the nature of roots


if discriminant > 0:
print("Real and Different Roots")
elif discriminant == 0:
print("Real and Same Roots")
else:
print("Complex Roots")

Output: Enter the coefficient a: Enter the coefficient b:


Python Code: Program_1_60.py

# Program for Task 60

# Create Dictionary with Pass and Fail Roll Numbers

result_dict = {
"Alice": 95,
"Bob": 30,
"Charlie": 75,
"David": 40
}

# Create tuples of pass and fail roll numbers


pass_roll_numbers = tuple(name for name, marks in result_dict.items() if marks >= 33)
fail_roll_numbers = tuple(name for name, marks in result_dict.items() if marks < 33)

print("Pass Roll Numbers:", pass_roll_numbers)


print("Fail Roll Numbers:", fail_roll_numbers)

Output: Pass Roll Numbers: ('Alice', 'Charlie', 'David')


Output: Fail Roll Numbers: ('Bob',)
Output:
Python Code: Program_1_61.py

# Program for Task 61

# Display Maximum, Minimum, and Average Marks from a Dictionary

marks_dict = {
"Alice": 90,
"Bob": 85,
"Charlie": 92,
"David": 88
}

# Calculate maximum, minimum, and average marks


max_marks = max(marks_dict.values())
min_marks = min(marks_dict.values())
avg_marks = sum(marks_dict.values()) / len(marks_dict)

print("Maximum Marks:", max_marks)


print("Minimum Marks:", min_marks)
print("Average Marks:", avg_marks)

Output: Maximum Marks: 92


Output: Minimum Marks: 85
Output: Average Marks: 88.75
Output:
Python Code: Program_1_62.py

# Program for Task 62

# Count Occurrences of Numbers in a List

numbers = [1, 2, 3, 2, 4, 1, 5, 2, 3, 5]

# Count occurrences of each number


occurrences = {num: numbers.count(num) for num in set(numbers)}

print("Number Occurrences:", occurrences)

Output: Number Occurrences: {1: 2, 2: 3, 3: 2, 4: 1, 5: 2}


Output:
Python Code: Program_1_63.py

# Program for Task 63

# Calculate Mean, Median, Mode, and Standard Deviation

marks = [85, 92, 78, 95, 88, 72, 90, 92, 88, 85, 78, 95, 90, 92, 88]

# Calculate mean, median, mode, and standard deviation


mean = sum(marks) / len(marks)
median = sorted(marks)[len(marks) // 2]
mode = max(set(marks), key=marks.count)
std_dev = (sum((x - mean) ** 2 for x in marks) / len(marks)) ** 0.5

print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
print("Standard Deviation:", std_dev)

Output: Mean: 87.2


Output: Median: 88
Output: Mode: 88
Output: Standard Deviation: 6.42079953484507
Output:
Python Code: Program_1_64.py

# Program for Task 64

# Count Occurrences of Characters in a Sentence

sentence = "hello world"

# Count occurrences of each character


char_occurrences = {char: sentence.count(char) for char in set(sentence)}

print("Character Occurrences:", char_occurrences)

Output: Character Occurrences: {'l': 3, 'r': 1, 'w': 1, 'd': 1, ' ': 1, 'h': 1, 'e': 1, 'o': 2}
Output:
Python Code: Program_1_65.py

# Program for Task 65

# Count Occurrences of Words in a Sentence

sentence = "hello world hello again world"

# Count occurrences of each word


word_occurrences = {word: sentence.split().count(word) for word in set(sentence.split())}

print("Word Occurrences:", word_occurrences)

Output: Word Occurrences: {'again': 1, 'hello': 2, 'world': 2}


Output:
Python Code: Program_1_66.py

# Program for Task 66

# Electric Bill Calculator

units_consumed = int(input("Enter units consumed: "))

# Assuming a simple calculation for demonstration


bill_amount = units_consumed * 5 # Replace with actual calculation

print("Electric Bill Amount:", bill_amount)

Output: Enter units consumed: Electric Bill Amount: 495


Output:
Python Code: Program_1_67.py

# Program for Task 67

# Income Tax Calculator

income = int(input("Enter your income: "))

# Assuming a simple calculation for demonstration


tax_amount = income * 0.1 # Replace with actual calculation

print("Income Tax Amount:", tax_amount)

Output: Enter your income:


Python Code: Program_1_68.py

# Program for Task 68

# GST Calculator

product_price = int(input("Enter product price: "))

# Assuming a simple calculation for demonstration


gst_amount = product_price * 0.18 # Replace with actual calculation

print("GST Amount:", gst_amount)

Output: Enter product price:


Python Code: Program_1_69.py

# Program for Task 69

# Stone / Paper / Scissors Game

import random

choices = ["Stone", "Paper", "Scissors"]

user_choice = input("Enter your choice (Stone/Paper/Scissors): ")


computer_choice = random.choice(choices)

print("Computer's Choice:", computer_choice)

if user_choice == computer_choice:
result = "It's a tie!"
elif (
(user_choice == "Stone" and computer_choice == "Scissors") or
(user_choice == "Paper" and computer_choice == "Stone") or
(user_choice == "Scissors" and computer_choice == "Paper")
):
result = "You win!"
else:
result = "You lose!"

print(result)

Output: Enter your choice (Stone/Paper/Scissors): Computer's Choice: Scissors


Output: You lose!
Output:
Python Code: Program_1_7.py

# Adhiraj Dhawan S6-C


# TASK 07: WAPP to read a year and check whether the year is a Leap year or not.
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print(year, "is a Leap Year")
else:
print(year, "is not a Leap Year")

Output: Enter a year:


Python Code: Program_1_70.py

# Program for Task 70

# Quiz Game (Nested List)

questions = [
["What is the capital of France?", "Paris"],
["Which planet is known as the Red Planet?", "Mars"],
["What is the largest mammal?", "Blue Whale"]
]

score = 0

for question in questions:


user_answer = input(question[0] + " ")
if user_answer.lower() == question[1].lower():
print("Correct!")
score += 1
else:
print(f"Wrong! The correct answer is {question[1]}.")

print("Your Score:", score)

Output: What is the capital of France? Wrong! The correct answer is Paris.
Output: Which planet is known as the Red Planet?
Python Code: Program_1_8.py

# Adhiraj Dhawan S6-C


# TASK 08: WAPP to read 3 sides (or angles) of a triangle and display the Nature of the triangle.
side1 = float(input("Enter the length of side 1: "))
side2 = float(input("Enter the length of side 2: "))
side3 = float(input("Enter the length of side 3: "))

if side1 == side2 == side3:


print("Equilateral Triangle")
elif side1 == side2 or side2 == side3 or side1 == side3:
print("Isosceles Triangle")
else:
print("Scalene Triangle")

Output: Enter the length of side 1: Enter the length of side 2:


Python Code: Program_1_9.py

# Adhiraj Dhawan S6-C


# TASK 09: WAPP to demonstrate all methods applicable on strings.
string = "Hello, World!"

# Display original string


print("Original String:", string)

# String methods
print("Uppercase:", string.upper())
print("Lowercase:", string.lower())
print("Titlecase:", string.title())
print("Capitalized:", string.capitalize())
print("Length:", len(string))
print("Count 'l':", string.count('l'))
print("Replace 'World' with 'Python':", string.replace("World", "Python"))
print("StartsWith 'Hello':", string.startswith("Hello"))
print("EndsWith 'World!':", string.endswith("World!"))

Output: Original String: Hello, World!


Output: Uppercase: HELLO, WORLD!
Output: Lowercase: hello, world!
Output: Titlecase: Hello, World!
Output: Capitalized: Hello, world!
Output: Length: 13
Output: Count 'l': 3
Output: Replace 'World' with 'Python': Hello, Python!
Output: StartsWith 'Hello': True
Output: EndsWith 'World!': True
Output:

You might also like