High Priority Programs
High Priority Programs
# Create a list
my_list = [1, 2, 3]
print("Original list:", my_list)
# Create a tuple
my_tuple = (10, 20, 30)
print("Original tuple:", my_tuple)
# Tuple concatenation
new_tuple = my_tuple + (40, 50)
print("Concatenated tuple:", new_tuple)
# Create a dictionary
my_dict = {"name": "Alice", "age": 25, "city": "New York"}
print("Original dictionary:", my_dict)
# Update a value
my_dict["age"] = 26
print("After updating 'age':", my_dict)
num1 = 10
num2 = 20
num3 = 15
largest = find_largest(num1, num2, num3)
print("The largest number is:", largest)
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
temp_in_celsius = 25
temp_in_fahrenheit = 77
PYTHON
a = 10
b = 20
print("Before swapping: a =", a, ", b =", b)
# Swapping values
a, b = b, a
print("After swapping: a =", a, ", b =", b)
PYTHON
import math
x1, y1 = 1, 2
x2, y2 = 4, 6
distance = distance_between_points(x1, y1, x2, y2)
print(f"Distance between points ({x1}, {y1}) and ({x2}, {y2}): {distance:.2f}")
PYTHON
def circulate_values(values):
# Shift the last element to the first position
values.insert(0, values.pop())
return values
x1, y1, z1 = 1, 2, 3
x2, y2, z2 = 4, 6, 8
distance = distance_3d(x1, y1, z1, x2, y2, z2)
print(f"Distance between 3D points: {distance:.2f}")
PYTHON
def generate_fibonacci(n):
series = [0, 1]
while len(series) < n:
series.append(series[-1] + series[-2])
return series
n = 10 # Number of terms
fibonacci_series = generate_fibonacci(n)
print("Fibonacci series:", fibonacci_series)
PYTHON
def number_pattern(rows):
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=" ")
print()
rows = 5
number_pattern(rows)
PYTHON
def pyramid_pattern(rows):
for i in range(1, rows + 1):
print(" " * (rows - i) + "* " * i)
rows = 5
pyramid_pattern(rows)
14. Items Present in a Library Using Lists and Tuples
Program to manage a library's inventory:
PYTHON
PYTHON
16. Materials Required for Construction of a Building (Operations on Lists and Tuples)
Program to manage building materials:
PYTHON
PYTHON
def word_count_and_longest(sentence):
words = sentence.split()
word_count = len(words)
longest_word = max(words, key=len)
return word_count, longest_word
import pygame
# Initialize Pygame
pygame.init()
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Quit Pygame
pygame.quit()
PYTHON
class IntegerToRoman:
def __init__(self):
self.numerals = {
1000: 'M', 900: 'CM', 500: 'D', 400: 'CD',
100: 'C', 90: 'XC', 50: 'L', 40: 'XL',
10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'
}
converter = IntegerToRoman()
number = 3549
roman_numeral = converter.int_to_roman(number)
print(f"{number} in Roman numeral is {roman_numeral}")
import pygame
# Initialize Pygame
pygame.init()
# Screen settings
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Bouncing Ball")
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Draw everything
screen.fill(white)
pygame.draw.circle(screen, red, ball_pos, ball_radius)
pygame.display.flip()
pygame.time.delay(10)
pygame.quit()
import pygame
# Initialize Pygame
pygame.init()
# Screen settings
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Car Race")
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()