Python Programmes
Python Programmes
def get_student_details():
marks = []
for i in range(6):
while True:
try:
else:
marks.append(mark)
break
except ValueError:
total_marks = sum(marks)
print("\nStudent Details:")
print(f"Name: {name}")
for i in range(6):
print(f"Percentage: {percentage:.2f}%")
get_student_details()
Student Details:
Roll Number: 32
Name: Daivik
Percentage: 97.67%
Student Details:
Roll Number: 33
Name: Parinith
Percentage: 92.50%
2. import math
def calculate_area_of_circle():
try:
if diameter < 0:
return
radius = diameter / 2
except ValueError:
calculate_area_of_circle()
3. def calculate_sum_and_average():
try:
average = total_sum / 3
except ValueError:
calculate_sum_and_average()
Outputs 1. Enter the first number: 2
4. def find_biggest_and_smallest():
try:
biggest = num1
smallest = num2
biggest = num2
smallest = num1
else:
if num1 == num2:
else:
except ValueError:
find_biggest_and_smallest()
5. def find_biggest_among_three():
try:
biggest = num1
biggest = num2
else:
biggest = num3
except ValueError:
find_biggest_among_three()
6. def test_number_sign():
try:
if number > 0:
else:
except ValueError:
test_number_sign()
7. def generate_report_card():
try:
marks = []
for i in range(6):
return
marks.append(mark)
total_marks = sum(marks)
grade = 'A+'
grade = 'A'
grade = 'B'
grade = 'C'
grade = 'D'
else:
grade = 'F'
print("\nReport Card:")
print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
except ValueError:
generate_report_card()
Percentage: 70.17%
Grade: B
Report Card:
Percentage: 99.67%
Grade: A+
8. def create_and_display_data_structures():
# Creating a list
# Creating a tuple
# Creating a dictionary
my_dict = {
'name': 'Nikunj',
'age': 15,
'city': 'Mangalore'}
print("List:")
print(my_list)
print("\nTuple:")
print(my_tuple)
print(f"{key}: {value}")
create_and_display_data_structures()
Output List:
Tuple:
Dictionary:
name: Nikunj
age: 15
city: Mangalore
my_list = []
my_list.append(1)
my_list.append(2)
my_list.insert(1, 'inserted')
my_list.extend([3, 4, 5])
my_list = [1, 2, 3, 4, 5, 6, 7]
# 3. Using pop() without an index to remove and return the last element
last_element = my_list.pop()
Removed element: 3
my_list = [7, 3, 1, 4, 9, 2, 8, 6, 5]
my_list.sort()
total_sum = 0
# Use a for loop to iterate through the list and calculate the sum
total_sum += number
if number % 2 == 0:
if number % 2 != 0:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
88 89 90 91 92 93 94 95 96 97 98 99 100
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86
88 90 92 94 96 98 100
current_number = 1
total_sum = 0
total_sum += current_number
current_number += 1
reversed_list = []
# Use a for loop to iterate through the original list in reverse order
reversed_list.append(original_list[i])