User Course File 648da648a2632a1e048f6f75eNWqjPi0i3Python Class 3 Assignment
User Course File 648da648a2632a1e048f6f75eNWqjPi0i3Python Class 3 Assignment
Q1. Write a Python program to find those numbers which are divisible by 7 and
multiples of 5, between 1500 and 2700 (both included).
Output:
1505,1540,1575,1610,1645,1680,1715,1750,1785,1820,1855,1890,1925,1960,1
995,2030,2065,2100,2135,2170,2205,2240,2275,2310,2345,2380,2415,2450,24
ills
85,2520,2555,2590,2625,2660,2695
Q2. Write a Python program that accepts a word from the user and reverses it.
Sk
INPUT: Input a word to reverse: Shailja
OUTPUT: ajliahS
a
Q3. Write a Python program that prints all the numbers from 0 to 6 except 3 and
at
6. Note : Use 'continue' statement.
Expected Output : 0 1 2 4 5
D
Q4. Write a Python program that prints each item and its corresponding type from
w
INPUT = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class":'V',
"section":'A'}]
OUTPUT:
G
Q5. Write a Python program to check the validity of passwords input by users.
Validation :
ills
At least 1 letter between [a-z] and 1 letter between [A-Z].
At least 1 number between [0-9].
At least 1 character from [$#@].
Sk
Minimum length 6 characters.
Maximum length 16 characters.
Expected Output : 1 1 2 3 5 8 13 21 34
ro
OUTPUT:
k is a consonant.
Q8. Write a Python program that takes a string as input and replaces all
occurrences of a given character with another character.
ills
Q9: Write a Python function to reverse a list at a specific location.
INPUT: [10,20,30,40,50,60,70,80]
start_pos = 2
Sk
end_pos = 4
OUTPUT: Reverse elements of the said list between index position 2 and 4
a
[10, 20, 50, 40, 30, 60, 70, 80]
at
Q10. Write a Python program that takes a string as input and checks if it is a
D
Q11. Write a Python program that takes a sentence as input and capitalizes the
first letter of each word.
G
INPUT:
list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]
OUTPUT: Common elements: [3, 4, 5]
ills
Python functions
Sk
Q. Write a Python function to calculate the factorial of a number (a non-negative
integer). The function accepts the number as an argument.
OUTPUT: 24
a
at
Q. Write a Python function that accepts a string and counts the number of upper-
and lower-case letters.
D
OUTPUT:
No. of Upper case characters : 3
ro
INPUT:5
Q. Write a Python function that takes a list of numbers as input and returns the
ills
average of the numbers.
INPUT: [1,2,3,4,5,6,7,8,9,10]
OUTPUT: 5.5
Sk
Q. Write a Python function that takes a list as input and returns a new list
containing only the unique elements from the input list.
a
INPUT: [1,2,3,4,1,2,0,0,1]
at
OUTPUT: [0, 1, 2, 3, 4]
D
Q. Write a Python function that takes two strings as input and checks if they are
anagrams (contain the same characters in any order).
INPUT:
w
Q.Write a Python function that takes a list and an element as input and returns
the number of occurrences of that element in the list.
INPUT:
input_list = [ 1,2,3,4,2,2,3,4,5,9,2,6]
Enter the element to count: 2
OUTPUT: Occurrences: 4
Q.Write a Python function that takes a list of tuples as input and returns the list
sorted based on the second element of each tuple.
INPUT:[(1, 3), (2, 1), (3, 2), (4, 5), (5, 4)]
OUTPUT: Sorted list of tuples: [(2, 1), (3, 2), (1, 3), (5, 4), (4, 5)]
ills
Q.Write a Python function that takes a list of integers as input and returns the
second largest element in the list.
Sk
INPUT: [3, 5, 2, 8, 9, 5, 1]
INPUT:
input_numbers = [1, 2, 3, 4, 5]
w
exponent = 3
ro
Q. Write a Python function that takes a list of integers as input and returns a new
list containing only the odd numbers.
INPUT:
ills
OUTPUT:
Sk
Perimeter of the circle: 25.132741228718345
Q. Write a Python program to create a person class. Include attributes like name,
a
country and date of birth. Implement a method to determine the person's age.
at
SAMPLE OUTPUT:
Person 1:
D
Country: France
w
Age: 60
Person 2:
G
Country: Canada
Age: 40
Person 3:
Country: USA
Age: 23
ills
Q. Write a Python program to create a calculator class. Include methods for
basic arithmetic operations.
SAMPLE INPUT:7,5
Sk
SAMPLE OUTPUT:
7 + 5 = 12
7-5=2 a
7 * 5 = 35
at
7/5 = 1.0
D
SAMPLE INPUT:
ro
Circle(5)
G
Triangle(3, 4, 5)
Square(6)
SAMPLE OUTPUT:
Circle:
Area: 78.53981633974483
Perimeter: 31.41592653589793
Triangle:
Area: 6.0
Perimeter: 12
Square:
ills
Area: 36
Perimeter: 24
Sk
a
at
D
w
ro
G