0% found this document useful (0 votes)
8 views8 pages

Program of Python

The document outlines a series of programming tasks for Python, categorized into five main problems focusing on basic programming, control statements, loops, string manipulation, and functions. Each problem includes multiple specific programming challenges aimed at developing fundamental skills in Python. The tasks range from simple input/output operations to more complex calculations and data structure manipulations.

Uploaded by

madaansaab339
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Program of Python

The document outlines a series of programming tasks for Python, categorized into five main problems focusing on basic programming, control statements, loops, string manipulation, and functions. Each problem includes multiple specific programming challenges aimed at developing fundamental skills in Python. The tasks range from simple input/output operations to more complex calculations and data structure manipulations.

Uploaded by

madaansaab339
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JKSKILLHUB [Link].

JKSKILLHUB PVT LTD


Problem based learning in Python
Mentor : Dr. Jasdeep Kaur

Problem 1 : Develop following basic programs in python to display on the screen and to
do some calculations

1. Write a program to display any message on the screen.


2. Write a program to read one integer, one Float, one Character type variable and
display the values of all three variables.
3. Write a program to read two integers, calculate sum, difference, product and division
of them and display the result.
4. Write a program to read radius of a circle, calculate its area and display the result.
(area = pi*r*r)
5. Write a program to read base and height of a triangle, calculate its area and display
the result. (area = ½*base*height)
6. Write a Program to convert days into years
7. Write a program to read side of a square, calculate its area and display the result.
(area = side*side)
8. Write a program to read length and width of a rectangle, calculate its area and display
the result. (area = length*width)
9. Write a program to calculate simple interest. (SI = principal*rate of interest*time/100)
10. Swap numbers
a. Swap two numbers using third variable.
b. Swap two numbers without using third variable.
11. Write a program to read marks obtained and maximum marks of a student and
calculate its percentage and display it.
12. Write a program to read two integers, divide them and store the result in third integer
type variable and display the value of all three variables.
13. Write a program to read two integers, divide them and store the result in third float
type variable and display the value of all three variables.
14. Write a program to read one integer, one float divides them and store the result in
third integer type variable and display the value of all three variables.
15. Write a program to read one integer, one float divides them and store the result in
third float type variable and display the value of all three variables.
16. Write a program to Convert temperature in Celsius to Fahrenheit . ((0C * 9/5)+32)
17. Write a program to convert Years into Days.
18. Write a program to Convert kilometres per hour to miles per hour.(1km = 0.6213712)

1
JKSKILLHUB [Link].

Problem 2 : Develop the following programs in python using control statement.

 If-else

1. Write a program to determine whether a person is eligible to vote.


2. Write a program to find maximum between two numbers.
3. Write a program to check whether a number is positive and negative.
4. Write a program to check whether a year is leap year or not.
5. Write a program to check whether a character is alphabet or not.
6. Write a program to check whether a character is uppercase or lowercase
alphabet.
7. Write a program to input angles of a triangle and check whether triangle is
valid or not.

 If – elif – else

1. Write a program to find maximum between three numbers.


2. Write a program to input any character and check whether it is alphabet,
digit or special character.
3. Write a program to test whether a number entered by the user is negative,
positive or equal to zero.
4. Write a program to input any alphabet and check whether it is vowel or
consonant.
5. Write a program to input month number and display the number of days in
that month.
6. Write a program to input marks of five subjects Physics, Chemistry,
Biology, Mathematics and Computer. Calculate percentage and grade.
7. Write a program to check whether the triangle is equilateral, isosceles or
scalene triangle.
8. Write a program to calculate profit of loss.

 Nested if

1. Write a program to check whether a number is divisible by 5 and 11 or not.


2. Write a program to check whether a number is divisible by 2, 5 and 6 or
not.
3. Let us write a program to input three numbers from user. Find maximum
between given three numbers

2
JKSKILLHUB [Link].

Program 3 : Develop the following programs in python using control statement (Loops).

 For-loop
 Write a program to display the “Hello world” n times.
 Write a program to find the first 10 natural numbers.
 Write a program to find the sum of 10 natural numbers.
 Write a program to find the factorial of a number.
 Write a program to find the first 10 odd and even numbers.
 Write a program to display the multiplication table.
 Write a program to display the cube of the first 5 natural numbers.
 Write a program to display Fibonacci series.
 Write a program to check if a number is prime or not.
 Write a program to display the:

*****
*****
*****
*****
*****

 Write a program to display the:


1
12
123
1234
12345
 Write a program to display the:
1
22
333
4444
333
22
1
 Write a program to display the:

*
***
*****
*******
*********

3
JKSKILLHUB [Link].

 Write a program to display the:

1
22
333
4444
55555
4444
333
22
1

 While-loop

 Write a program to display the “Hello world” n times.


 Write a program to find the first 10 natural numbers.
 Write a program to find the sum of 10 natural numbers.
 Write a program to display the multiplication table.
 Write a program to find the first 10 odd and even number.
 Write a program to display the cube of the first 5 natural numbers.
 Write a program to display Fibonacci series.
 Write a program to check a number is palindrome or not.
 Write a program to check a number is Armstrong or not.
 Write a program to display the:

*
**
***
****
*****
 Write a program to display the:

1
22
333
4444
55555
 Write a program to display the:

4
JKSKILLHUB [Link].

*
***
*****
*******
*********

Program 4 : Develop the following programs in python using string .

1. Write a Python program to calculate the length of a string.


2. Program to read a string and display it in reverse order-display one character
per line do not create a reverse string, just display in reverse order.
3. Program to read a string and display it in the form:
For ex: „Try‟
T y
r r
y T
4. Write a program to input an integer and check if it contains any 0 in it.
5. Program that displays this the following pattern without using any nested loop.
#
##
###
####
#####
6. Write a program to input a string and check if it is a palindrome string using a
string slice.
7. Write a program to input a string and display the number of upper- and lower-
case letters in it.
8. Python program to display the even length words in a string.

 String Functions in python :-

 lower(): Converts all uppercase characters in a string into lowercase


 upper(): Converts all lowercase characters in a string into uppercase
 title(): Convert string to title case
 swapcase(): Swap the cases of all characters in a string
 capitalize(): Convert the first character of a string to uppercase
 index(): Returns the position of the first occurrence of a substring in a string
 isalnum(): Checks whether all the characters in a given string is alphanumeric
or not.
 isalpha(): Returns “True” if all characters in the string are alphabets
 isdecimal(): Returns true if all characters in a string are decimal
 isdigit(): Returns “True” if all characters in the string are digits

5
JKSKILLHUB [Link].

 replace(): Replaces all occurrences of a substring with another substring

 List Methods in Python:-

 append(): Used for appending and adding elements to the end of the List.
 copy(): It returns a shallow copy of a list
 clear(): This method is used for removing all items from the list.
 count(): These methods count the elements
 extend(): Adds each element of the iterable to the end of the List
 index(): Returns the lowest index where the element appears.
 insert(): Inserts a given element at a given index in a list.
 pop(): Removes and returns the last value from the List or the given index
value.
 remove(): Removes a given object from the List.
 reverse(): Reverses objects of the List in place.
 sort(): Sort a List in ascending, descending, or user-defined order
 min(): Calculates the minimum of all the elements of the List
 max(): Calculates the maximum of all the elements of the List
 Write a program to read and display 2-D array.
 Write a program to Add two matrices.
 Write a program to subtract two matrices.
 Write a program to check whether a matrix is symmetric or not.
(A matrix is symmetric if A[i][j] == A[j][i])
 Write a program to product of two matrices.
 Write a program to transpose of matrices.

 Python Set Methods:-

 add(): Adds a given element to a set


 clear(): Removes all elements from the set
 copy(): Returns a shallow copy of the set
 difference(): Returns a set that is the difference between two sets
 difference_update(): Updates the existing caller set with the difference
between two sets
 discard(): Removes the element from the set
 intersection(): Returns a set that has the intersection of all sets
 intersection_update(): Updates the existing caller set with the intersection of
sets
 isdisjoint(): Checks whether the sets are disjoint or not
 issubset(): Returns True if all elements of a set A are present in another set B
 issuperset(): Returns True if all elements of a set A occupies set B

6
JKSKILLHUB [Link].

 pop(): Returns and removes a random element from the set


 remove(): Removes the element from the set
 symmetric_difference(): Returns a set which is the symmetric difference
between the two sets
 symmetric_difference_update(): Updates the existing caller set with the
symmetric difference of sets
 union() : Returns a set that has the union of all sets
 update(): Adds elements to the set

 Tuple methods in Python:-

 len(): This method returns number of elements in a tuple.


 max(): This method returns largest element of a tuple.
 min(): This method returns smallest element of a tuple.

 Python Dictionary :-

 clear(): Removes all Items


 copy(): Returns the Shallow Copy of a Dictionary
 get(): Returns Value of The Key
 items(): returns view of dictionary's (key, value) pair
 keys(): Returns View Object of All Keys
 pop() : removes and returns element having given key
 popitem(): Returns & Removes Latest Element From Dictionary
 update(): Updates the Dictionary values()
 Write a Python program to count the number of characters (character
frequency) in a string.
 program to get a string from a given string where all occurrences of its first
char have been changed to '$', except the first char itself.
 program to remove characters that have odd index values in a given string.
 Python program to remove a newline in Python.

Program 5 : Develop the following programs in python using function .

1. Write a program to create a function that takes two arguments, name and age, and
display their value.
2. Write a Python function to sum all the numbers in a list.
3. Write a Python function to find the maximum of three numbers.
4. Write a Python function to multiply all the numbers in a list.
5. Write a Python program to reverse a string.
6. Write a program to create function calculation() such that it can accept two variables
and calculate addition and subtraction. Also, it must return both addition and
subtraction in a single function.

7
JKSKILLHUB [Link].

7. Write a Python function to calculate the factorial.


8. Write a function that inputs a number and display this the multiplication table of that
number.

You might also like