0% found this document useful (0 votes)
3 views4 pages

Python Topicwise Knowledge Test Problems-1

The document outlines a series of Python programming problems categorized by topics such as Variables, Operators, Control Flow, Loops, and more. Each category contains multiple tasks that focus on different aspects of Python programming, including data types, control structures, functions, and object-oriented programming. Additionally, it includes advanced challenges like creating a caching decorator and implementing a command-line application.
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)
3 views4 pages

Python Topicwise Knowledge Test Problems-1

The document outlines a series of Python programming problems categorized by topics such as Variables, Operators, Control Flow, Loops, and more. Each category contains multiple tasks that focus on different aspects of Python programming, including data types, control structures, functions, and object-oriented programming. Additionally, it includes advanced challenges like creating a caching decorator and implementing a command-line application.
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

Python Topic-wise Knowledge Test Problems

Variables and Data Types

1 Write a program that takes an integer, float, and string from the user and prints their types.
2 Create variables for int, float, string, bool, list, tuple, set, and dictionary. Print their types and
example values.

3 Write a program that converts temperature from Celsius to Fahrenheit.

Operators

1 Write a program that takes two numbers and demonstrates arithmetic, comparison, and logical
operators.

2 Check whether a number lies between 10 and 50 using logical operators.

Control Flow (if/else)

1 Write a program that checks whether a number is positive, negative, or zero.


2 Write a program that determines whether a year is a leap year.

Loops

1 Print numbers from 1 to 50 using a for loop.


2 Write a program to calculate the sum of numbers from 1 to n.
3 Print a multiplication table for a given number.

Lists

1 Create a list of numbers and find the largest element without using max().
2 Remove duplicate elements from a list.
3 Rotate a list to the right by k positions.

Tuples
1 Create a tuple and unpack its values into variables.
2 Write a program that swaps two numbers using tuple unpacking.

Sets

1 Given two sets, find union, intersection, and difference.


2 Remove duplicate elements from a list using a set.

Dictionaries

1 Create a dictionary of student names and marks. Print the student with highest marks.
2 Count frequency of characters in a string using a dictionary.

Functions

1 Write a function that returns the factorial of a number.


2 Write a function that checks whether a number is prime.
3 Write a function that returns the second largest number in a list.

*args and **kwargs

1 Write a function that accepts any number of positional arguments and returns their sum.
2 Write a function that accepts keyword arguments and prints key-value pairs.

Lambda, Map, Filter

1 Use lambda to sort a list of tuples based on the second value.


2 Use map() to square numbers in a list.
3 Use filter() to extract even numbers from a list.

Generators

1 Write a generator that yields Fibonacci numbers.


2 Write a generator that yields numbers divisible by 5 up to 100.
Object-Oriented Programming

1 Create a class 'Car' with attributes brand, model, and speed and a method accelerate().
2 Create a class 'Student' that tracks name and marks and calculates grade.

Inheritance and Polymorphism

1 Create a base class Shape and subclasses Circle and Rectangle with an area() method.
2 Demonstrate method overriding using parent and child classes.

Exception Handling

1 Write a program that safely divides two numbers and handles division by zero.
2 Write a program that handles file not found exceptions.

File Handling

1 Write a program that reads a text file and counts the number of lines.
2 Write a program that writes user input into a file.

Decorators

1 Write a decorator that prints 'Function started' and 'Function ended'.


2 Create a decorator that measures execution time of a function.

Context Managers

1 Create a custom context manager that opens and closes a file safely.
2 Implement a context manager using a class with __enter__ and __exit__.

Regular Expressions

1 Write a program that extracts all email addresses from a text.


2 Validate whether a string is a valid phone number.
Advanced Python Challenges

1 Implement your own version of Python's enumerate().


2 Create a caching decorator that stores results of previous calls.
3 Build a small command-line todo application using Python.

You might also like