Holiday Homework

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Holiday Homework

Submission Instructions

1. Solve any 20 problems following the template given below.


2. Each solution should include:
a) The problem statement as a comment.
b) The Python program with appropriate comments explaining key parts of the code.
c) A description of variables used.
d) Output along with one sample input.
3. Compile all 20 solutions into a single Word document.
4. Ensure each problem solution is clearly separated and labeled in the document.

Example:
# Question 1: Write a Python program to find the sum of two integers.

# Define a function to add two numbers


def add_two_numbers(a, b):
# Calculate the sum and return the value
return a + b

# Get two numbers from the user


number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))

# Call the function to get the sum


result = add_two_numbers(number1, number2)

# Output: Display the result


print("The sum of ",number1," and ",number2, " is ",result)

#variable description-
# number1 – int data type– stores first number input by the user
#number2 – int – stores second number input by the user
#a- int – the first number to be added(local to the function add_two_numbers)
#b- int – the second number to be added(local to the function add_two_numbers)

Sample Input:
Enter the first number: 23
Enter the second number: 34
Output:
The sum of 23 and 34 is 57
(i) Write Python program for a school to identify special student IDs where the sum of the
digits of the ID is a prime number. The program should include the user-defined functions -
sum_of_digits(number) to calculate the sum of digits in the ID. Display appropriate
message for the user input and the output.

(ii) Write a program to input a number and check and print whether it is a pronic number or not.
(Pronic number is the number which is the product of two consecutive integers)
Examples: 12 = 3 x 4, 20 = 4 x 5, 42 = 6 x 7

(iii) Write a program to calculate the fines for overdue library books. The fine amount increases
the longer a book is overdue, as follows:
No fine for the first two days.
Dhs. 0.50 per day for the next five days (i.e., from day 3 to day 7).
Dhs. 1.00 per day for each day beyond 7 days.

Accept the number of overdue days as input and display the total fine with the appropriate
message.

(iv) Write a program that displays the following menu and executes the options as per the
user’s choice.
1. Convert hours to minutes
2. Convert minutes to hours
For option 1, accept time as number of hours and then convert it to minutes. For option 2,
accept time as number of minutes and then convert it to hours.

(v) Consider a list containing the exam scores of the students: [85, 90, 75, 92, 88, 78, 84, 79,
93, 87]. Write a Python program to compute and display the average score, the highest
score, and the lowest score in the list.

(vi) Start with a list of numbers. Convert this list into a tuple. Then, write a function that takes
this tuple, adds 5 to each element, and returns the result as a list.

(vii) Create a Python script that generates an acronym from a given string. For example, "North
Atlantic Treaty Organization" should return "NATO".

(viii) Write a Python program that scans a string and prints out all characters that appear
consecutively more than once. For example, given the string "mississippi", the output
should be "ssp" because the characters 's' and 'p' appear consecutively more than once.
Ensure the program preserves the order and frequency of characters as they appear in the
input string.

(ix) Write a program that would print the 3 digit Armstrong numbers.
An Armstrong number of three digits is an integer such that the sum of the cubes of its
digits is equal to the number itself.
371 is an Armstrong number since 33 + 73 + 13 = 371.
(x) Write a program to accept a number and display each digit in its equivalent word form.
Example: Input: 6735
Output Six Seven Three Five

(xi) Write a program to store the first 20 Buzz numbers in a list and display the list.
A buzz number is a number that ends with 7 or is divisible by 7.

(xii) Write a program that accepts an integer from the user. The program should find all sets of
consecutive positive integers that sum up to the given number and print these numbers.

Sample output
Enter a number: 15
consecutive numbers that sum to 15:
1, 2, 3, 4, 5
4, 5, 6
7, 8

(xiii) Write a program to accept 10 values in a list. Calculate the sum of the single-digit numbers
and the sum of two-digit numbers separately and display both sums.

(xiv) Write a program to input sentence S and the letter L. Convert sentence and letter to
uppercase, then count and display the total number of words starting with the letter L.

(xv) Write a program to find the sum of the following series. Create user defined functions
Fractions() and Squares() to achieve this:
(i) 1/2 + 1/3 + 1/4 + .......+ 1/10
(ii) x+x2+x3+…..+xn
(xvi) Write a program that accepts N integers as input from the user. The program should
remove all duplicate elements from the list and print the modified list.

(xvii) Create a Hangman game that randomly selects a word from a list, allows the player to
guess letters, and provides feedback on the number of remaining attempts.

(xviii) Create a simple Quiz game that asks the user a series of questions stored in a dictionary
and keeps track of the score.

(xix) Create a Rock-Paper-Scissors game that allows the user to play against the computer, with
the computer making random choices.

(xx) Write a Python program to calculate the single-digit sum of a given number.
Example:
Input: 4678
Process: 4 + 6 + 7 + 8 = 25 → 2 + 5 = 7
Output: 7
(xxi) Write a program that prints the Prime numbers between a range of numbers, say m and n,
where m and n must be greater than 0 and n must be greater than m.

(xxii) Write a program that would display only the Palindrome numbers between a range of
numbers, say m and n, where m and n must be greater than 0 and n must be greater than
m.
Palindrome number is a number, which is the same when read forwards and
backwards.
eg. 121 is a Palindrome number
1234 is not a Palindrome number
1331 is a Palindrome number

(xxiii) Write a program that initializes two lists with a set of values. The two lists can be of different
lengths. Compare the 2 lists and display the elements found in both.
Example:
A contains: 5, 6, 12, 3, 8, 9, 10
B contains: 23, 4, 5,15, 8,12, 50, 43, 6
Output: 5, 6, 12, 8

(xxiv) Write a program that initializes two integer lists A and B with a set of values. The two lists
can be of different lengths. Display the elements of list B that are not in list A.
Example
List A contains: 5, 6, 12, 3, 8, 9, 10, 78, 46, 35, 43, 87, 90
List B contains: 23, 4, 5, 15, 8, 12, 50, 43, 6
Ouput: 23, 4, 15, 50, 43

(xxv) Write a program that initializes two integer lists with a set of values. The two lists can be of
different lengths. Merge the two lists into one list and display.
Example:
A contains: 5, 6, 12, 3, 8, 9, 10
B contains: 23, 4, 5,15, 8,12, 50, 43, 6
C should contain: 5, 6, 12, 3, 8, 9, 10, 23, 4, 5,15, 8,12, 50, 43, 6
Output: 5, 6, 12, 3, 8, 9, 10, 23, 4, 5,15, 8,12, 50, 43, 6

(xxvi) Write a menu driven program which would print the following patterns:
(a) (b) (c) (d) (e)
1 1 @*@*@ 1 4444
22 12 @*@* 2 3 333
333 123 @*@ 4 5 6 22
4444 1234 @* 7 8 9 10 1
55555 12345 @ 22
333
4444

You might also like