Python Programming Test
Python Programming Test
Name: _______________________________
Date: ________________________________
Instructions:
Create a list named fruits containing the elements "apple," "banana," and "orange."
Append "grape" to the list.
Write a Python function that takes an integer as an argument and returns "Even" if
the number is even and "Odd" if it's odd.
Define a function called cube that takes a number as a parameter and returns its
cube.
Given the string sentence = "Python programming is fun!", extract and print
only the word "programming."
Question 7: Dictionaries (2 points)
Create a dictionary named person with keys "name" and "age," and values "John"
and 25, respectively.
Write Python code to open a file named "example.txt" in write mode, write the string
"Hello, file handling!" to it, and then close the file.
Create a class Circle with a constructor that takes the radius as a parameter. Add a
method area that calculates and returns the area of the circle.
Question 11: List Comprehension (2 points)
Generate a list containing the squares of the numbers from 1 to 5 using list
comprehension.
Import the math module and use it to calculate the square root of 16.
Create a decorator named logger that prints the name of the function being called
before calling it. Apply this decorator to a sample function.
Question 15: NumPy (3 points)
Install and import the NumPy library. Create a NumPy array with values ranging from
1 to 5.
Install and import the Pandas library. Create a Pandas DataFrame with columns
"Name" and "Age" and add two rows of data.
Write a regular expression to validate a phone number in the format (XXX) XXX-
XXXX.
Install the Flask framework and create a simple web application with a route that
returns "Hello, Flask!"
Question 19: API Request (3 points)
Use the requests library to make a GET request to a public API (e.g.,
https://jsonplaceholder.typicode.com/todos/1) and print the response.
Install the sqlite3 library, create a SQLite database, and insert a record into a table
named "students" with columns "id," "name," and "age."
End of Test