0% found this document useful (0 votes)
7 views9 pages

User Course File 648da648a2632a1e048f6f75eNWqjPi0i3Python Class 3 Assignment

Uploaded by

Nilanjana Das
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)
7 views9 pages

User Course File 648da648a2632a1e048f6f75eNWqjPi0i3Python Class 3 Assignment

Uploaded by

Nilanjana Das
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
You are on page 1/ 9

Python Conditional Statements and loops

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

the following list.


ro

INPUT = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class":'V',
"section":'A'}]
OUTPUT:
G

Type of 1452 is <class 'int'>


Type of 11.23 is <class 'float'>
Type of (1+2j) is <class 'complex'>
Type of True is <class 'bool'>
Type of w3resource is <class 'str'>
Type of (0, -1) is <class 'tuple'>
Type of [5, 12] is <class 'list'>
Type of {'class': 'V', 'section': 'A'} is < class 'dict'>

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.

INPUT: Input your password:S3r@100a


a
OUTPUT:Valid Password
at
Q6. Write a Python program to get the Fibonacci series between 0 and 50.
D

Note : The Fibonacci Sequence is the series of numbers :


0, 1, 1, 2, 3, 5, 8, 13, 21, ....
Every next number is found by adding up the two numbers before it.
w

Expected Output : 1 1 2 3 5 8 13 21 34
ro

Q7. Write a Python program to check whether an alphabet is a vowel or


consonant.
G

OUTPUT:

Input a letter of the alphabet: k

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.

INPUT: Enter a string: We study at GrowDataSkills

Enter the character to replace: G

Enter the replacement character: H

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

palindrome (reads the same forwards and backward).

INPUT: Enter a string: GrowDataSkills


w

OUTPUT: It is not a palindrome.


ro

Q11. Write a Python program that takes a sentence as input and capitalizes the
first letter of each word.
G

INPUT: Enter a sentence: we are growdataskills

OUTPUT: Capitalized sentence: We Are Growdataskills


Q12. Write a Python program that takes two lists as input and returns a new list
containing the common elements between the two lists.

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.

INPUT: Input a number to compute the factorial: 4

OUTPUT: 24
a
at
Q. Write a Python function that accepts a string and counts the number of upper-
and lower-case letters.
D

INPUT: The quick Brow Fox'


w

OUTPUT:
No. of Upper case characters : 3
ro

No. of Lower case Characters : 13


G

Q. Write a Python function to check whether a number falls within a given


range(3,9)

INPUT:5

OUTPUT: 5 is in the range


Q. Write a Python function that takes an integer as input and checks if it is a
prime number.

INPUT: Enter an integer: 13

OUTPUT: It is a prime number.

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

Enter the first string: race


ro

Enter the second string: care

OUTPUT: They are anagrams.


G

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]

OUTPUT: Second largest element: 8


a
at
Q.Write a Python lambda function that takes a list of numbers and an exponent n
as input and returns a new list with each element raised to the power of n.
D

INPUT:

input_numbers = [1, 2, 3, 4, 5]
w

exponent = 3
ro

OUTPUT: [1, 16, 81, 256, 625]


G

Q. Write a Python function that takes a list of integers as input and returns a new
list containing only the odd numbers.

INPUT: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


OUTPUT: [1,3,5,7,9]
Python Object-Oriented Programming

Q. Write a Python program to create a class representing a Circle. Include


methods to calculate its area and perimeter.

INPUT:

Radius of the circle: 4

ills
OUTPUT:

Area of the circle: 50.26548245743669

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

Name: Ferdi Odilia

Country: France
w

Date of Birth: 1962-07-12


ro

Age: 60

Person 2:
G

Name: Shweta Maddox

Country: Canada

Date of Birth: 1982-10-20

Age: 40
Person 3:

Name: Elizaveta Tilman

Country: USA

Date of Birth: 2000-01-01

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

Q. Write a Python program to create a class that represents a shape. Include


methods to calculate its area and perimeter. Implement subclasses for different
w

shapes like circle, triangle, and square.

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

You might also like