In learning to code, after a point, students need to apply these coding concepts to solve practical problems that are more relevant to real life. One of the challenges with useful problems is that they are often vague, and many assumptions must be made while arriving at an acceptable solution. Here is a list of coding problems that can provide students with some practice in solving such questions.
Note: that in several problems, specific values are mentioned, which you should use as input to your function in a suitable format. The code should work even if we change the values.
Q1. A teacher has 30 students in a class. Each student has a list of 5 exam scores. Write a program to calculate and display the average score of each student.
Q2. A store has 10 different items. The store manager wants to apply a 10% discount on every item that costs more than INR 50. Write a program to display the updated prices for each item.
There is a running competition with 20 participants. You need to find the top 3 participants who ran the fastest.
Q3. A movie website has ratings from 5 users for 3 different movies. Each user gives a rating between 1 to 5. Write a program to find the highest-rated movie.
Q4. A bank records the daily transactions of 20 customers. Some transactions are deposits, and some are withdrawals. Write a program that calculates the total deposit and withdrawal amounts for each customer.
Q5. A cafeteria has a menu of 15 items. Every day, the cafeteria gives a random discount of 5%, 10%, or 15% on all items. Write a program to calculate the new prices for each item after the discount is applied.
Q6.A school election has 4 candidates, and 30 students cast their votes. Write a program to count how many votes each candidate received and display the winner.
Q7.A library has a collection of 25 books, and each book is either available or checked out. Write a program to count the number of available books and the number of books that are checked out.
Q8. A university records the attendance of 100 students for 10 classes. Write a program to calculate the percentage of attendance for each student and display the list of students who attended less than 90% of the classes.
Q9. A sports coach needs to select 5 players from a pool of 12 for a basketball team. Write a program to calculate the number of different ways the coach can select 5 players.
Q10. A fitness tracker records the number of steps a person takes for 30 days. Write a program to find the average steps per day, and identify the days when the user exceeded 10,000 steps.
Q11. A fitness app is tracking the steps of users daily. A user logs 3,500 steps on Monday, 6,200 on Tuesday, and 4,800 on Wednesday. On Thursday, they plan to do a workout for 45 minutes instead of walking. The app recommends users take at least 5,000 steps a day on average. Write a program to check if the user has met their step goal by Wednesday.
Q12. A parking garage charges INR 30 for the first hour and INR 20 for each additional hour. A car entered the garage at 9 AM and left at 2 PM. The car owner also bought a coffee from the café inside the garage for INR 63. Write a program to calculate the total parking fee.
Q13. A household is monitoring its water usage. The total water consumption for the month is 25,000 liters. The water company charges INR 50 per 1,000 liters. The family uses 5,000 liters for gardening. Write a program to calculate the total water bill for the household, excluding gardening usage.
Q14. Given a dictionary with student names and a list of booleans representing their attendance over 5 days, return a dictionary with student names and their attendance percentage.
Q15. Given a username string, return True if the username is valid (must be between 6 and 12 characters and contain only alphanumeric characters).
Q16. Given the current room conditions, find out if the air conditioner should be turned on.
Q17. Given an email string, return True if it is a valid email ID.
Q18. Given a car number, return True if the input is a valid number in India.
Q19. Write a function to check if a given string is a valid PAN card number.
Q20. Write a function to check if a given number is a valid mobile number in India.
Q21. Given a string, check if it’s a valid postal code in India.
Q22. Given a string, return True if it is a valid hex color code.
Q23. An invoice ID at a company starts with two uppercase letters, followed by four digits, and ends with an uppercase letter (e.g., “AB1234X”). Write a function to check if the input string matches this format.
Q25. Given a set of coin denominations and a target amount, find the minimum number of coins required to make that amount.
Q26. A company offers discounts based on a tiered system, where each product’s discount is determined by a percentage based on its price. Write a Python program that calculates the total discounted price of a list of products. The program should take a list of product prices (eg. 50, 150, 600, 1200) and apply the respective discount to each product, then return the total discounted cost.
Q27. Imagine you’re tracking your monthly expenses and want to know how much you’re spending on each category, like groceries, rent, transportation, etc. Write a Python program that calculates the total expenses for each category and shows you where most of your money is going. This could involve asking the user to enter expenses in different categories, summing up each category’s expenses, and displaying the results and the category with the highest expenditure.
Q28. You are taking an exam with four types of questions: 10 questions are 4 marks each, 10 questions are 3 marks each, 10 questions are 2 marks each, and 5 questions are 1 mark each. For each correct answer, you receive full marks, while each incorrect answer results in a deduction of 1 mark. You answered 5 questions from the 4-mark section, 4 questions from the 3-mark section, 7 questions from the 2-mark section, and 3 questions from the 1-mark section. Out of these, 8 answers were incorrect. Calculate the total marks you achieved, and your percentage score, and determine if you passed the exam, given that the passing mark is 80. Write a function that takes these numbers as input and does all the calculations to return the output.
Q29. You are given a dictionary representing the inventory of a store. The keys are the item names, and the values are tuples containing the available stock and price. Write a Python function that checks if the requested quantity of the item is available. If available, reduce the stock by the quantity purchased and return the total price for that purchase. If not available, return a message stating “Not enough stock.”
Q30. Create a function mask_email(email) that takes an email address and hides part of it for privacy, showing only the first two characters of the username and the domain.