Python Programming Exercises for Intermediate Developers offers a comprehensive resource tailored to individuals advancing from basic to intermediate proficiency in Python programming. This section presents a curated selection of exercises designed to challenge and expand the skills of developers who have already mastered the fundamentals of Python. Covering a broad spectrum of intermediate-level topics such as object-oriented programming, asynchronous programming, and advanced data structures, each exercise is meticulously crafted to deepen understanding and promote growth. Whether utilized for self-study or as part of a structured learning curriculum, this inclusive guide empowers intermediate developers to refine their Python skills and tackle more complex programming challenges with confidence.
Functions: Hello and Goodbye Develop a Python program where the main function should look like this:
SayHello()
SayGoodbye()
You must define the functions SayHello and SayGoodbye, and they will be called from within the main function.
|
Parameterized Function Develop a Python program where the main function should look like this:
SayHello("John")
SayGoodbye()
You must define the functions SayHello and SayGoodbye, and they will be called from within the main function. As shown in the example, SayHello must accept a string as a parameter.
|
Value-Returning Function Develop a Python program where the main function should look like this:
x = 3
y = 5
print(sum(x, y))
You must define the function `sum`, and it will be called from within the main function. As shown in the example, it must accept two integers as parameters and return an integer (the sum of those two numbers).
|
Value-Returning Function V2 Develop a Python program where the main function should look like this:
def main():
print("\"Hello, how are you\" contains {0} spaces".format(count_spaces("Hello, how are you")))
You must define the function `count_spaces`, and it will be called from within the main function.
As shown in the example, it must accept a string as a parameter and return an integer (the number of spaces in that string).
|
Centered Text Function Develop a Python function named "get_int" that displays the text received as a parameter, prompts the user for an integer number, repeats if the number is not between the minimum and maximum values indicated as parameters, and finally returns the entered number:
age = get_int("Enter your age", 0, 150)
would become:
Enter your age: 180
Not a valid answer. Must be no more than 150.
Enter your age: -2
Not a valid answer. Must be no less than 0.
Enter your age: 20
(the value for the variable "age" would be 20)
|
Underline Text Function Develop a Python function that can center the text on the screen (assuming a screen width of 80 characters) and then underline it with hyphens:
write_underlined("Hello!")
|
Array Summation Function Develop a Python program to calculate the sum of the elements in an array. The main function should look like this:
def main():
example = [20, 10, 5, 2]
print("The sum of the example array is {}".format(sum_elements(example)))
You must define the function `sum_elements`, and it will be called from within the main function. As shown in the example, it must accept an array as a parameter and return the sum of its elements.
|
Double Value Function Develop a Python function named "double" to calculate and return an integer that is twice its input. For example, double(7) should return 14.
|
Function Double with Mutable Parameter Develop a Python function named "double_value" to calculate the double of an integer number and modify the data passed as an argument. Since Python does not use reference parameters in the same way as C#, we will use a mutable type like a list to achieve similar behavior. For example:
def double_value(num):
num[0] *= 2
x = [5]
double_value(x)
print(x[0])
would display 10
|
Function Swap with Mutable Parameters Develop a Python program with a function called "swap" to exchange the values of two integer variables, which are passed by reference.
For example:
x = 5 y = 3 swap(x, y) print(f"x={x}, y={y}") (which should print "x=3, y=5") |
Showing 10 to 92 Python Programming Exercises
List of Python Programming Exercises for Intermediate Grouped
All levels of the Python language and for everyone
Python Programming Exercises for all levels. Whether you are a beginning programmer or an advanced programmer. You can practice Python Programming Exercises online, easy and fast