This document lists 37 Python programming problems covering topics like arithmetic, comparison, logical and bitwise operators, control flow, strings, recursion, classes, exceptions, file handling and more. The problems involve writing programs to calculate grades, factorials, Fibonacci series, palindromes and more.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views
CSA318-List of Programs
This document lists 37 Python programming problems covering topics like arithmetic, comparison, logical and bitwise operators, control flow, strings, recursion, classes, exceptions, file handling and more. The problems involve writing programs to calculate grades, factorials, Fibonacci series, palindromes and more.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
Programming in Python Lab (CSA318)
List of Programs
Program1. Write a program using arithmetic operators.
Program2. Write a program using comparison operators. Program3. Write a program using assignment operators. Program4. Write a program using bitwise operators. Program5. Write a program using logical operators. Program6. Write a program using highest precedence to lowest. Program7. Write a program to find the given number is even or odd. Program8. Write a program to find the given number is prime or not. Program9. Write a program to check whether a person is eligible to vote or not. Program10. Write a program to find the greatest number among three numbers. Program11. Write a program to find the grade of a student. If marks>=90 then grade is A+. If marks>=80<90 then grade is A. If marks>=70<80 then grade is B. If marks>=60<70 then grade is C. Program12. Write an program to print the table of 5 using for loop. Program13. Write a program to print star (a) * ** *** **** ***** (b) ***** **** *** ** * Program14. Write a program to print the number (a) 1 22 333 4444 55555 (b) 1 12 123 1234 12345 Program15. Write a program using control statements Continue Break Program16. Write a program using inbuilt string function. Program17. Write a program to find the factorial of a number using recursion. Program18. Write a program to find the Fibonacci series using recursion. Program19. Write a Python program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ... shows the first 10 ugly numbers. Note: 1 is typically treated as an ugly number. Program20. Write a Python program to compute the sum of the even-valued terms in the Fibonacci sequence whose values do not exceed one million. Note: Fibonacci series is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Program21. Write a Python program to find whether it contains an additive sequence or not. The additive sequence is a sequence of numbers where the sum of the first two numbers is equal to the third one. Sample additive sequence: 6,6,12,18,30 In the above sequence 6+6 =12,6+12=18,12+18=30… Program22. Write a Python program to check a sequence of numbers is an arithmetic progression or not. In mathematics, an arithmetic progression or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For example, the sequence 5, 7, 9, 11, 13, 15 ... is an arithmetic progression with common difference of 2. Program23. Write a Python program to check a sequence of numbers is a geometric progression or not. In mathematics, a geometric progression or geometric sequence is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly, 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2. Program24. Write a Python program to find the largest palindrome made from the product of two 4-digit numbers. According Wikipedia - A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical". The term palindromic is derived from palindrome, which refers to a word (such as rotor or racecar) whose spelling is unchanged when its letters are reversed. The first 30 palindromic numbers (in decimal) are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, … The largest palindrome made from the product of two 3-digit numbers is 913 * 993 = 906609. Note: 9999 * 9901 = 906609 Program25. Write a Python program to find the smallest positive number that is evenly divisible by all of the numbers from 1 to 30. 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Result: 2329089562800.0 Program26. Write a Python program to find the first triangle number to have over n(given) divisors. A triangular number is a number that is the sum of all of the natural numbers up to a certain number. For example, 10 is a triangular number because 1 + 2 + 3 + 4 = 10. The first 25 triangular numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, and 351. A triangular number is calculated by the equation: n(n+1)/2
The factors of the first five triangle numbers:
1: 1 3: 1, 3 6: 1, 2, 3, 6 10: 1, 2, 5, 10 15: 1, 3, 5, 15 In the above list 6 is the first triangle number to have over four divisors. Program27. Write a Python program to find the sum of the digits of a given number. In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120 and the sum of the digits in the number 5! is 1 + 2 +0 = 3 Program28. Write a python program that reads text from a file and writes it into another file but in the reverse order. Program29. Write a menu driven program that maintains a file DIRECTORY that stores the name and telephone number of a person. The program must allow users to add new contacts, search a contact based on name, search a contact based on phone number, update the number, update the name, and delete a contact. Program30. Write a Program to perform following operations on given string. (a) Extract the first n characters of a string. (b) Copy n characters of a string from the mth position in another string. (c) Delete the last character of a string. (d) Append a string to another string. (e) Create a mirror of the given string. Program31. Write a program that finds square root of a number. Throw an exception if a negative number is entered. Program32. Write a program that has a class TIME. Enter the time When a user started an online test and completes the test. Subtract the two times values and display the duration in which the test was completed. Throw exceptions whenever need arises (like invalid data, or if start time is greater than completion time). Program33. Write a program that overloads the /= operator in FRACTION class. Throw an exception if a divide by zero exception occurs. Program 34. write a program that has a class train with the data members no of seats 1 st, no of seats 2, tier, and no_of_chars and member functions to set and display data. derive a class reservation that has data members seats booked 1st, seats booked two tier and seats booked three tier and function two book and cancel ticket and display status. Program35. Write a program that has a class Distance with members- kms and meters. Derive classes school and office which store the distance from your house to school and office along with other details. Program36. Write a menu driven program to add or delete items from your inventory of stationery items. You can use a dictionary to store item and the brand. Program37. Write a Program that displays the details of a cricket player. The details must include his name, matched played, run rate, wickets taken, maiden overs, overs played, number of centuries, and half centuries, etc.