Python Practice for Beginners: 15 Hands-On Problems

Author's photo

  • online practice

Want to put your Python skills to the test? Challenge yourself with these 15 Python practice exercises taken directly from our Python courses!

There’s no denying that solving Python exercises is one of the best ways to practice and improve your Python skills . Hands-on engagement with the language is essential for effective learning. This is exactly what this article will help you with: we've curated a diverse set of Python practice exercises tailored specifically for beginners seeking to test their programming skills.

These Python practice exercises cover a spectrum of fundamental concepts, all of which are covered in our Python Data Structures in Practice and Built-in Algorithms in Python courses. Together, both courses add up to 39 hours of content. They contain over 180 exercises for you to hone your Python skills. In fact, the exercises in this article were taken directly from these courses!

In these Python practice exercises, we will use a variety of data structures, including lists, dictionaries, and sets. We’ll also practice basic programming features like functions, loops, and conditionals. Every exercise is followed by a solution and explanation. The proposed solution is not necessarily the only possible answer, so try to find your own alternative solutions. Let’s get right into it!

Python Practice Problem 1: Average Expenses for Each Semester

John has a list of his monthly expenses from last year:

He wants to know his average expenses for each semester. Using a for loop, calculate John’s average expenses for the first semester (January to June) and the second semester (July to December).

Explanation

We initialize two variables, first_semester_total and second_semester_total , to store the total expenses for each semester. Then, we iterate through the monthly_spending list using enumerate() , which provides both the index and the corresponding value in each iteration. If you have never heard of enumerate() before – or if you are unsure about how for loops in Python work – take a look at our article How to Write a for Loop in Python .

Within the loop, we check if the index is less than 6 (January to June); if so, we add the expense to first_semester_total . If the index is greater than 6, we add the expense to second_semester_total .

After iterating through all the months, we calculate the average expenses for each semester by dividing the total expenses by 6 (the number of months in each semester). Finally, we print out the average expenses for each semester.

Python Practice Problem 2: Who Spent More?

John has a friend, Sam, who also kept a list of his expenses from last year:

They want to find out how many months John spent more money than Sam. Use a for loop to compare their expenses for each month. Keep track of the number of months where John spent more money.

We initialize the variable months_john_spent_more with the value zero. Then we use a for loop with range(len()) to iterate over the indices of the john_monthly_spending list.

Within the loop, we compare John's expenses with Sam's expenses for the corresponding month using the index i . If John's expenses are greater than Sam's for a particular month, we increment the months_john_spent_more variable. Finally, we print out the total number of months where John spent more money than Sam.

Python Practice Problem 3: All of Our Friends

Paul and Tina each have a list of their respective friends:

Combine both lists into a single list that contains all of their friends. Don’t include duplicate entries in the resulting list.

There are a few different ways to solve this problem. One option is to use the + operator to concatenate Paul and Tina's friend lists ( paul_friends and tina_friends ). Afterwards, we convert the combined list to a set using set() , and then convert it back to a list using list() . Since sets cannot have duplicate entries, this process guarantees that the resulting list does not hold any duplicates. Finally, we print the resulting combined list of friends.

If you need a refresher on Python sets, check out our in-depth guide to working with sets in Python or find out the difference between Python sets, lists, and tuples .

Python Practice Problem 4: Find the Common Friends

Now, let’s try a different operation. We will start from the same lists of Paul’s and Tina’s friends:

In this exercise, we’ll use a for loop to get a list of their common friends.

For this problem, we use a for loop to iterate through each friend in Paul's list ( paul_friends ). Inside the loop, we check if the current friend is also present in Tina's list ( tina_friends ). If it is, it is added to the common_friends list. This approach guarantees that we test each one of Paul’s friends against each one of Tina’s friends. Finally, we print the resulting list of friends that are common to both Paul and Tina.

Python Practice Problem 5: Find the Basketball Players

You work at a sports club. The following sets contain the names of players registered to play different sports:

How can you obtain a set that includes the players that are only registered to play basketball (i.e. not registered for football or volleyball)?

This type of scenario is exactly where set operations shine. Don’t worry if you never heard about them: we have an article on Python set operations with examples to help get you up to speed.

First, we use the | (union) operator to combine the sets of football and volleyball players into a single set. In the same line, we use the - (difference) operator to subtract this combined set from the set of basketball players. The result is a set containing only the players registered for basketball and not for football or volleyball.

If you prefer, you can also reach the same answer using set methods instead of the operators:

It’s essentially the same operation, so use whichever you think is more readable.

Python Practice Problem 6: Count the Votes

Let’s try counting the number of occurrences in a list. The list below represent the results of a poll where students were asked for their favorite programming language:

Use a dictionary to tally up the votes in the poll.

In this exercise, we utilize a dictionary ( vote_tally ) to count the occurrences of each programming language in the poll results. We iterate through the poll_results list using a for loop; for each language, we check if it already is in the dictionary. If it is, we increment the count; otherwise, we add the language to the dictionary with a starting count of 1. This approach effectively tallies up the votes for each programming language.

If you want to learn more about other ways to work with dictionaries in Python, check out our article on 13 dictionary examples for beginners .

Python Practice Problem 7: Sum the Scores

Three friends are playing a game, where each player has three rounds to score. At the end, the player whose total score (i.e. the sum of each round) is the highest wins. Consider the scores below (formatted as a list of tuples):

Create a dictionary where each player is represented by the dictionary key and the corresponding total score is the dictionary value.

This solution is similar to the previous one. We use a dictionary ( total_scores ) to store the total scores for each player in the game. We iterate through the list of scores using a for loop, extracting the player's name and score from each tuple. For each player, we check if they already exist as a key in the dictionary. If they do, we add the current score to the existing total; otherwise, we create a new key in the dictionary with the initial score. At the end of the for loop, the total score of each player will be stored in the total_scores dictionary, which we at last print.

Python Practice Problem 8: Calculate the Statistics

Given any list of numbers in Python, such as …

 … write a function that returns a tuple containing the list’s maximum value, sum of values, and mean value.

We create a function called calculate_statistics to calculate the required statistics from a list of numbers. This function utilizes a combination of max() , sum() , and len() to obtain these statistics. The results are then returned as a tuple containing the maximum value, the sum of values, and the mean value.

The function is called with the provided list and the results are printed individually.

Python Practice Problem 9: Longest and Shortest Words

Given the list of words below ..

… find the longest and the shortest word in the list.

To find the longest and shortest word in the list, we initialize the variables longest_word and shortest_word as the first word in the list. Then we use a for loop to iterate through the word list. Within the loop, we compare the length of each word with the length of the current longest and shortest words. If a word is longer than the current longest word, it becomes the new longest word; on the other hand, if it's shorter than the current shortest word, it becomes the new shortest word. After iterating through the entire list, the variables longest_word and shortest_word will hold the corresponding words.

There’s a catch, though: what happens if two or more words are the shortest? In that case, since the logic used is to overwrite the shortest_word only if the current word is shorter – but not of equal length – then shortest_word is set to whichever shortest word appears first. The same logic applies to longest_word , too. If you want to set these variables to the shortest/longest word that appears last in the list, you only need to change the comparisons to <= (less or equal than) and >= (greater or equal than), respectively.

If you want to learn more about Python strings and what you can do with them, be sure to check out this overview on Python string methods .

Python Practice Problem 10: Filter a List by Frequency

Given a list of numbers …

… create a new list containing only the numbers that occur at least three times in the list.

Here, we use a for loop to iterate through the number_list . In the loop, we use the count() method to check if the current number occurs at least three times in the number_list . If the condition is met, the number is appended to the filtered_list .

After the loop, the filtered_list contains only numbers that appear three or more times in the original list.

Python Practice Problem 11: The Second-Best Score

You’re given a list of students’ scores in no particular order:

Find the second-highest score in the list.

This one is a breeze if we know about the sort() method for Python lists – we use it here to sort the list of exam results in ascending order. This way, the highest scores come last. Then we only need to access the second to last element in the list (using the index -2 ) to get the second-highest score.

Python Practice Problem 12: Check If a List Is Symmetrical

Given the lists of numbers below …

… create a function that returns whether a list is symmetrical. In this case, a symmetrical list is a list that remains the same after it is reversed – i.e. it’s the same backwards and forwards.

Reversing a list can be achieved by using the reverse() method. In this solution, this is done inside the is_symmetrical function.

To avoid modifying the original list, a copy is created using the copy() method before using reverse() . The reversed list is then compared with the original list to determine if it’s symmetrical.

The remaining code is responsible for passing each list to the is_symmetrical function and printing out the result.

Python Practice Problem 13: Sort By Number of Vowels

Given this list of strings …

… sort the list by the number of vowels in each word. Words with fewer vowels should come first.

Whenever we need to sort values in a custom order, the easiest approach is to create a helper function. In this approach, we pass the helper function to Python’s sorted() function using the key parameter. The sorting logic is defined in the helper function.

In the solution above, the custom function count_vowels uses a for loop to iterate through each character in the word, checking if it is a vowel in a case-insensitive manner. The loop increments the count variable for each vowel found and then returns it. We then simply pass the list of fruits to sorted() , along with the key=count_vowels argument.

Python Practice Problem 14: Sorting a Mixed List

Imagine you have a list with mixed data types: strings, integers, and floats:

Typically, you wouldn’t be able to sort this list, since Python cannot compare strings to numbers. However, writing a custom sorting function can help you sort this list.

Create a function that sorts the mixed list above using the following logic:

  • If the element is a string, the length of the string is used for sorting.
  • If the element is a number, the number itself is used.

As proposed in the exercise, a custom sorting function named custom_sort is defined to handle the sorting logic. The function checks whether each element is a string or a number using the isinstance() function. If the element is a string, it returns the length of the string for sorting; if it's a number (integer or float), it returns the number itself.

The sorted() function is then used to sort the mixed_list using the logic defined in the custom sorting function.

If you’re having a hard time wrapping your head around custom sort functions, check out this article that details how to write a custom sort function in Python .

Python Practice Problem 15: Filter and Reorder

Given another list of strings, such as the one below ..

.. create a function that does two things: filters out any words with three or fewer characters and sorts the resulting list alphabetically.

Here, we define filter_and_sort , a function that does both proposed tasks.

First, it uses a for loop to filter out words with three or fewer characters, creating a filtered_list . Then, it sorts the filtered list alphabetically using the sorted() function, producing the final sorted_list .

The function returns this sorted list, which we print out.

Want Even More Python Practice Problems?

We hope these exercises have given you a bit of a coding workout. If you’re after more Python practice content, head straight for our courses on Python Data Structures in Practice and Built-in Algorithms in Python , where you can work on exciting practice exercises similar to the ones in this article.

Additionally, you can check out our articles on Python loop practice exercises , Python list exercises , and Python dictionary exercises . Much like this article, they are all targeted towards beginners, so you should feel right at home!

You may also like

problem solving through python programming

How Do You Write a SELECT Statement in SQL?

problem solving through python programming

What Is a Foreign Key in SQL?

problem solving through python programming

Enumerate and Explain All the Basic Elements of an SQL Query

Say "Hello, World!" With Python Easy Max Score: 5 Success Rate: 96.23%

Python if-else easy python (basic) max score: 10 success rate: 89.70%, arithmetic operators easy python (basic) max score: 10 success rate: 97.40%, python: division easy python (basic) max score: 10 success rate: 98.68%, loops easy python (basic) max score: 10 success rate: 98.10%, write a function medium python (basic) max score: 10 success rate: 90.31%, print function easy python (basic) max score: 20 success rate: 97.27%, list comprehensions easy python (basic) max score: 10 success rate: 97.68%, find the runner-up score easy python (basic) max score: 10 success rate: 94.17%, nested lists easy python (basic) max score: 10 success rate: 91.71%, cookie support is required to access hackerrank.

Seems like cookies are disabled on this browser, please enable them to open this website

Python Wife Logo

  • Computer Vision
  • Problem Solving in Python
  • Intro to DS and Algo
  • Analysis of Algorithm
  • Dictionaries
  • Linked Lists
  • Doubly Linked Lists
  • Circular Singly Linked List
  • Circular Doubly Linked List
  • Tree/Binary Tree
  • Binary Search Tree
  • Binary Heap
  • Sorting Algorithms
  • Searching Algorithms
  • Single-Source Shortest Path
  • Topological Sort
  • Dijkstra’s
  • Bellman-Ford’s
  • All Pair Shortest Path
  • Minimum Spanning Tree
  • Kruskal & Prim’s

Problem-solving is the process of identifying a problem, creating an algorithm to solve the given problem, and finally implementing the algorithm to develop a computer program .

An algorithm is a process or set of rules to be followed while performing calculations or other problem-solving operations. It is simply a set of steps to accomplish a certain task.

In this article, we will discuss 5 major steps for efficient problem-solving. These steps are:

  • Understanding the Problem
  • Exploring Examples
  • Breaking the Problem Down
  • Solving or Simplification
  • Looking back and Refactoring

While understanding the problem, we first need to closely examine the language of the question and then proceed further. The following questions can be helpful while understanding the given problem at hand.

  • Can the problem be restated in our own words?
  • What are the inputs that are needed for the problem?
  • What are the outputs that come from the problem?
  • Can the outputs be determined from the inputs? In other words, do we have enough information to solve the given problem?
  • What should the important pieces of data be labeled?

Example : Write a function that takes two numbers and returns their sum.

  • Implement addition
  • Integer, Float, etc.

Once we have understood the given problem, we can look up various examples related to it. The examples should cover all situations that can be encountered while the implementation.

  • Start with simple examples.
  • Progress to more complex examples.
  • Explore examples with empty inputs.
  • Explore examples with invalid inputs.

Example : Write a function that takes a string as input and returns the count of each character

After exploring examples related to the problem, we need to break down the given problem. Before implementation, we write out the steps that need to be taken to solve the question.

Once we have laid out the steps to solve the problem, we try to find the solution to the question. If the solution cannot be found, try to simplify the problem instead.

The steps to simplify a problem are as follows:

  • Find the core difficulty
  • Temporarily ignore the difficulty
  • Write a simplified solution
  • Then incorporate that difficulty

Since we have completed the implementation of the problem, we now look back at the code and refactor it if required. It is an important step to refactor the code so as to improve efficiency.

The following questions can be helpful while looking back at the code and refactoring:

  • Can we check the result?
  • Can we derive the result differently?
  • Can we understand it at a glance?
  • Can we use the result or mehtod for some other problem?
  • Can you improve the performance of the solution?
  • How do other people solve the problem?

Trending Posts You Might Like

  • File Upload / Download with Streamlit
  • Seaborn with STREAMLIT
  • Dijkstra’s Algorithm in Python
  • Greedy Algorithms in Python

Author : Bhavya

problem solving through python programming

  • Runestone in social media: Follow @iRunestone Our Facebook Page
  • Table of Contents
  • Assignments
  • Peer Instruction (Instructor)
  • Peer Instruction (Student)
  • Change Course
  • Instructor's Page
  • Progress Page
  • Edit Profile
  • Change Password
  • Scratch ActiveCode
  • Scratch Activecode
  • Instructors Guide
  • About Runestone
  • Report A Problem
  • This Chapter
  • 1. Introduction' data-toggle="tooltip" >

Problem Solving with Algorithms and Data Structures using Python ¶

PythonDS Cover

By Brad Miller and David Ranum, Luther College

There is a wonderful collection of YouTube videos recorded by Gerry Jenkins to support all of the chapters in this text.

  • 1.1. Objectives
  • 1.2. Getting Started
  • 1.3. What Is Computer Science?
  • 1.4. What Is Programming?
  • 1.5. Why Study Data Structures and Abstract Data Types?
  • 1.6. Why Study Algorithms?
  • 1.7. Review of Basic Python
  • 1.8.1. Built-in Atomic Data Types
  • 1.8.2. Built-in Collection Data Types
  • 1.9.1. String Formatting
  • 1.10. Control Structures
  • 1.11. Exception Handling
  • 1.12. Defining Functions
  • 1.13.1. A Fraction Class
  • 1.13.2. Inheritance: Logic Gates and Circuits
  • 1.14. Summary
  • 1.15. Key Terms
  • 1.16. Discussion Questions
  • 1.17. Programming Exercises
  • 2.1.1. A Basic implementation of the MSDie class
  • 2.2. Making your Class Comparable
  • 3.1. Objectives
  • 3.2. What Is Algorithm Analysis?
  • 3.3. Big-O Notation
  • 3.4.1. Solution 1: Checking Off
  • 3.4.2. Solution 2: Sort and Compare
  • 3.4.3. Solution 3: Brute Force
  • 3.4.4. Solution 4: Count and Compare
  • 3.5. Performance of Python Data Structures
  • 3.7. Dictionaries
  • 3.8. Summary
  • 3.9. Key Terms
  • 3.10. Discussion Questions
  • 3.11. Programming Exercises
  • 4.1. Objectives
  • 4.2. What Are Linear Structures?
  • 4.3. What is a Stack?
  • 4.4. The Stack Abstract Data Type
  • 4.5. Implementing a Stack in Python
  • 4.6. Simple Balanced Parentheses
  • 4.7. Balanced Symbols (A General Case)
  • 4.8. Converting Decimal Numbers to Binary Numbers
  • 4.9.1. Conversion of Infix Expressions to Prefix and Postfix
  • 4.9.2. General Infix-to-Postfix Conversion
  • 4.9.3. Postfix Evaluation
  • 4.10. What Is a Queue?
  • 4.11. The Queue Abstract Data Type
  • 4.12. Implementing a Queue in Python
  • 4.13. Simulation: Hot Potato
  • 4.14.1. Main Simulation Steps
  • 4.14.2. Python Implementation
  • 4.14.3. Discussion
  • 4.15. What Is a Deque?
  • 4.16. The Deque Abstract Data Type
  • 4.17. Implementing a Deque in Python
  • 4.18. Palindrome-Checker
  • 4.19. Lists
  • 4.20. The Unordered List Abstract Data Type
  • 4.21.1. The Node Class
  • 4.21.2. The Unordered List Class
  • 4.22. The Ordered List Abstract Data Type
  • 4.23.1. Analysis of Linked Lists
  • 4.24. Summary
  • 4.25. Key Terms
  • 4.26. Discussion Questions
  • 4.27. Programming Exercises
  • 5.1. Objectives
  • 5.2. What Is Recursion?
  • 5.3. Calculating the Sum of a List of Numbers
  • 5.4. The Three Laws of Recursion
  • 5.5. Converting an Integer to a String in Any Base
  • 5.6. Stack Frames: Implementing Recursion
  • 5.7. Introduction: Visualizing Recursion
  • 5.8. Sierpinski Triangle
  • 5.9. Complex Recursive Problems
  • 5.10. Tower of Hanoi
  • 5.11. Exploring a Maze
  • 5.12. Dynamic Programming
  • 5.13. Summary
  • 5.14. Key Terms
  • 5.15. Discussion Questions
  • 5.16. Glossary
  • 5.17. Programming Exercises
  • 6.1. Objectives
  • 6.2. Searching
  • 6.3.1. Analysis of Sequential Search
  • 6.4.1. Analysis of Binary Search
  • 6.5.1. Hash Functions
  • 6.5.2. Collision Resolution
  • 6.5.3. Implementing the Map Abstract Data Type
  • 6.5.4. Analysis of Hashing
  • 6.6. Sorting
  • 6.7. The Bubble Sort
  • 6.8. The Selection Sort
  • 6.9. The Insertion Sort
  • 6.10. The Shell Sort
  • 6.11. The Merge Sort
  • 6.12. The Quick Sort
  • 6.13. Summary
  • 6.14. Key Terms
  • 6.15. Discussion Questions
  • 6.16. Programming Exercises
  • 7.1. Objectives
  • 7.2. Examples of Trees
  • 7.3. Vocabulary and Definitions
  • 7.4. List of Lists Representation
  • 7.5. Nodes and References
  • 7.6. Parse Tree
  • 7.7. Tree Traversals
  • 7.8. Priority Queues with Binary Heaps
  • 7.9. Binary Heap Operations
  • 7.10.1. The Structure Property
  • 7.10.2. The Heap Order Property
  • 7.10.3. Heap Operations
  • 7.11. Binary Search Trees
  • 7.12. Search Tree Operations
  • 7.13. Search Tree Implementation
  • 7.14. Search Tree Analysis
  • 7.15. Balanced Binary Search Trees
  • 7.16. AVL Tree Performance
  • 7.17. AVL Tree Implementation
  • 7.18. Summary of Map ADT Implementations
  • 7.19. Summary
  • 7.20. Key Terms
  • 7.21. Discussion Questions
  • 7.22. Programming Exercises
  • 8.1. Objectives
  • 8.2. Vocabulary and Definitions
  • 8.3. The Graph Abstract Data Type
  • 8.4. An Adjacency Matrix
  • 8.5. An Adjacency List
  • 8.6. Implementation
  • 8.7. The Word Ladder Problem
  • 8.8. Building the Word Ladder Graph
  • 8.9. Implementing Breadth First Search
  • 8.10. Breadth First Search Analysis
  • 8.11. The Knight’s Tour Problem
  • 8.12. Building the Knight’s Tour Graph
  • 8.13. Implementing Knight’s Tour
  • 8.14. Knight’s Tour Analysis
  • 8.15. General Depth First Search
  • 8.16. Depth First Search Analysis
  • 8.17. Topological Sorting
  • 8.18. Strongly Connected Components
  • 8.19. Shortest Path Problems
  • 8.20. Dijkstra’s Algorithm
  • 8.21. Analysis of Dijkstra’s Algorithm
  • 8.22. Prim’s Spanning Tree Algorithm
  • 8.23. Summary
  • 8.24. Key Terms
  • 8.25. Discussion Questions
  • 8.26. Programming Exercises

Acknowledgements ¶

We are very grateful to Franklin Beedle Publishers for allowing us to make this interactive textbook freely available. This online version is dedicated to the memory of our first editor, Jim Leisy, who wanted us to “change the world.”

Indices and tables ¶

Search Page

Creative Commons License

  • Problem Solving using Python - WS 18/19

problem solving through python programming

Programming requires multiple steps, from understanding the problem, designing a solution, coding, testing and debugging it into a running and correct program. Moreover, this program should be easy to understand and consequently modify. Balancing all of these concerns is a challenge for novice programmers. In this course, we will learn to solve programming problems in a methodical and thoughtful manner using the Python language. We will do so by applying a specific model for programming problem solving and tackling real problems. The course requires a background in programming, at least one introductory course.

Please read this if you wonder whether you should take this course or not.

Instructors

  • Shlomi Hod - shlomi.hod <AT> uni-potsdam.de
  • Ilia Kurenkov - ilia.kurenkov <AT> uni-potsdam.de

Time and place

Campus 3 - Griebnitzsee ( map )

  • Lecture - Mondays - 14:15-15:45 - House 1, Room 2.32 (3.01.2.32)
  • Lab - Wednesdays - 16:15-17:45 - House 4, Room 1.03 (3.04.1.03)
  • Office Hours - Wednesdays - 12:00-14:00, House 4, Room 2.01 (3.04.2.01)

Announcements

Fifthteenth week, february 4.

  • Please fill the End of Course - Evaluation and Feedback Survey until this Friday (08/02).
  • The final exam will take place at 18/02 (Monday) 14:00-17:00 in the computer lab - House 4, Room 1.03 (3.04.1.03). The problems in the studio would be good preparation.

Fourteenth Week, January 28

  • The course mini-project was uploaded to week 14.

Twelfth Week, January 14

  • The complete solution of the Sudoku problem is in the week’s lab link.

Eleventh Week, January 7

  • Homework 11 was uploaded, and its deadline is in three weeks.
  • Week 13 - Numpy vs. Git
  • Final exam date
  • Whether to solve ANLP’s CYK assignment in class

Tenth Week, December 17

  • After the Xmas break, we will solve in the lecture the Viterbi algorithm problem. We can relate to specific issues if you send us until 31/12/18 your solution. Of course, we will not show any of your code - it will be used only to extract general points.

Eighth Week, December 3

  • The midterm exam will take place next Wednesday (12/12) 15:00-18:00 in the computer lab - House 4, Room 1.03 (3.04.1.03). The problems in the studio would be good preparation. Recursion won’t be on the exam.

Seventh Week, November 28

  • The deadline for homework 5 (one-liners and image editor) is extended to 2/12 23:59 (Sunday).
  • Please read the clarification note in Piazza regarding “PPM file lines and Image Rows” in homework 5.

Sixth Week, November 19

  • If you plan to take this course for credit, you must enroll in PULS until 20/11.
  • Note that the deadline for homework 3 and 4 is 20/11 (this Wednesday).

Fifth Week, November 12

  • Milestone I - The function generate_word_ngram takes in the first argument - document_path - a path to a single file. That is explained in the docstring and it is suggested by the argument name. The text above the function states wrongly that it should take a path to a directory of files. We’ll fix the text for the next year.
  • Milestone III - The returned list of tuples should be ordered by the overlap score in descending order (largest to the smallest).
  • The feedbacks and grades for homework 1 were published in OK website .
  • Note that the deadline for homework 3 and 4 is 20/11.
  • In case you weren’t in the lab of week 4 (7/11), contact us to know which program you should test in homework 4.

Fourth Week, November 5

  • If you’ve downloaded homework 3 before 8/11 19h, please download it again. There was a mistake in the test of Milestone III.

Third Week, October 29

  • From now on, the lecture will take place in Haus 1 (the building with the Mensa), Room 2.32 . The time stays the same, 14:15-15:45. The lab is not affected by this.
  • Note that the deadline for homework 1 is on this Tuesday at 23:59. Make sure that you submit it correctly with the OK system by running the appropriate cells in Jupyter Notebook.
  • This Wednesday (31/10) there won’t be a Lab, because it is a day off in the University due to the Reformation Day. The office hours will take place on Thursday (1/11) 10:00-12:00 at the lobby of the first floor in house 4 (where the lab is located) in Griebnitzsee campus.

Second Week, October 22

  • You can find the rest of the “readability measure” part in the slides of lecture 2.
  • Next Wednesday (31/10) there won’t be a Lab, because it is a day off in the University due to the Reformation Day. The office hours will take place on Thursday (1/11) 10:00-12:00 at the lobby of the first floor in house 4 (where the lab is located) in Griebnitzsee campus.
  • In order to submit your homework to the OK system (homework auto-grading), you should have a Gmail account. You can use your personal address or create a new one for the course. Please send us your Gmail in Piazza or by email.

First Week, October 15

  • We will have a mini “ Installfests ” (Installation + Fest) for Anaconda and Jupyter Notebook before the lecture, 13:00-14:00 on Monday (22/10) at the lobby of the first floor in house 4 (where the lab is located) in Griebnitzsee campus. Bring your computers!
  • Please fill the pre-course form
  • To gain an access to the lab computers, please fill your university credentials here .
  • You can register for the course in PULS .
  • Signup to the course in Piazza . You should use your @uni-potsdam.de email address.
  • Follow the instructions in the setup page on your computer.

First class

  • Our first lecture will take place on the first day of the semester, Monday, the 15/10.
  • We will start at 14:15 SHARP .
  • The lecture will be ended 15 minutes earlier than usual, at 15:30.
  • Please fill the pre-course form until Sunday, the 14/10 .

Schedule is subject to change

#May Motivation Use code MAY10 for extra 10% off

30-days Money-Back Guarantee

Programming and Problem Solving Using Python

Learn Python Programming from installation to application development

English [CC]

Lectures - 32

Duration - 8 hours

Training 5 or more people ?

Get your team access to 10000+ top Tutorials Point courses anytime, anywhere.

Course Description

This is Beginners Course, which helps you to understand Python programming language from scratch.

This course has comprehensive collection of

Theory & Programming videos

18 Online MCQ Tests, Notes as per SPPU

Theory Question Bank

Program Source Codes

Mini Projects and 

numerous coding problems

Why should I take this course?

Learn how to Solve Real Programming Problems with a Focus on Teaching Problem Solving Skills

Understand Python as an Object Oriented and Functional Programming Language

Explained each and every point in very lucid and detailed way

when you complete our course you will be expert in python

Much useful for SPPU students struggling with PPS subject without having any knowledge of computer science

You can build your own logic to answer every question in exam without mugging up answers from the textbooks

Prime objective is to give students a basic introduction to programming and problem solving with computer language Python. And to introduce students not merely to the coding of computer programs, but to computational thinking, the methodology of computer programming, and the principles of good program design including modularity and encapsulation.

  • To understand problem solving, problem solving aspects, programming and to know about various program design tools.
  • To learn problem solving with computers
  • To learn basics, features and future of Python programming.
  • To acquaint with data types, input output statements, decision making, looping and functions in Python
  • To learn features of Object Oriented Programming using Python
  • To acquaint with the use and benefits of files handling in Python

Prerequisites

No programming or knowledge of computer needed. You will learn everything you need to know

Programming and Problem Solving Using Python

Check out the detailed breakdown of what’s inside the course

Instructor Details

EnggTutes

Course Certificate

Use your certificate to make a career change or to advance in your current career.

sample Tutorialspoint certificate

Our students work with the Best

adobe logo

Related Video Courses

Annual membership.

Become a valued member of Tutorials Point and enjoy unlimited access to our vast library of top-rated Video Courses

Annual Membership

Online Certifications

Master prominent technologies at full length and become a valued certified professional.

Online Certifications

1800-202-0515

  • Why Python?
  • The Anaconda Distribution of Python
  • Installing Anaconda on Windows
  • Installing Anaconda on MacOS
  • Installing Anaconda on Linux
  • Installing Python from Python.org
  • Review Questions

Orientation

Introduction.

Welcome to the world of problem solving with Python! This first Orientation chapter will help you get started by guiding you through the process of installing Python on your computer. By the end of this chapter, you will be able to:

Describe why Python is a useful computer language for problem solvers

Describe applications where Python is used

Detail advantages of Python over other programming languages

Know the cost of Python

Know the difference between Python and Anaconda

Install Python on your computer

Install Anaconda on your computer

swayam-logo

Programming, Data Structures And Algorithms Using Python

Note: This exam date is subjected to change based on seat availability. You can check final exam date on your hall ticket.

Page Visits

Course layout, books and references, instructor bio.

problem solving through python programming

Prof. Madhavan Mukund

Course certificate.

  • Assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. 
  • ( All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments). 
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam - out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100

problem solving through python programming

DOWNLOAD APP

problem solving through python programming

Solving Transportation Problem using Linear Programming in Python

Learn how to use Python PuLP to solve transportation problems using Linear Programming.

In this tutorial, we will broaden the horizon of linear programming problems. We will discuss the Transportation problem. It offers various applications involving the optimal transportation of goods. The transportation model is basically a minimization model.

The transportation problem is a type of Linear Programming problem. In this type of problem, the main objective is to transport goods from source warehouses to various destination locations at minimum cost. In order to solve such problems, we should have demand quantities, supply quantities, and the cost of shipping from source and destination. There are m sources or origin and n destinations, each represented by a node. The edges represent the routes linking the sources and the destinations.

problem solving through python programming

In this tutorial, we are going to cover the following topics:

Transportation Problem

The transportation models deal with a special type of linear programming problem in which the objective is to minimize the cost. Here, we have a homogeneous commodity that needs to be transferred from various origins or factories to different destinations or warehouses.

Types of Transportation problems

  • Balanced Transportation Problem :  In such type of problem, total supplies and demands are equal.
  • Unbalanced Transportation Problem : In such type of problem, total supplies and demands are not equal.

Methods for Solving Transportation Problem:

  • NorthWest Corner Method
  • Least Cost Method
  • Vogel’s Approximation Method (VAM)

Let’s see one example below. A company contacted the three warehouses to provide the raw material for their 3 projects.

problem solving through python programming

This constitutes the information needed to solve the problem. The next step is to organize the information into a solvable transportation problem.

Formulate Problem

Let’s first formulate the problem. first, we define the warehouse and its supplies, the project and its demands, and the cost matrix.

Initialize LP Model

In this step, we will import all the classes and functions of pulp module and create a Minimization LP problem using LpProblem class.

Define Decision Variable

In this step, we will define the decision variables. In our problem, we have various Route variables. Let’s create them using  LpVariable.dicts()  class.  LpVariable.dicts()  used with Python’s list comprehension.  LpVariable.dicts()  will take the following four values:

  • First, prefix name of what this variable represents.
  • Second is the list of all the variables.
  • Third is the lower bound on this variable.
  • Fourth variable is the upper bound.
  • Fourth is essentially the type of data (discrete or continuous). The options for the fourth parameter are  LpContinuous  or  LpInteger .

Let’s first create a list route for the route between warehouse and project site and create the decision variables using LpVariable.dicts() the method.

Define Objective Function

In this step, we will define the minimum objective function by adding it to the LpProblem  object. lpSum(vector)is used here to define multiple linear expressions. It also used list comprehension to add multiple variables.

In this code, we have summed up the two variables(full-time and part-time) list values in an additive fashion.

Define the Constraints

Here, we are adding two types of constraints: supply maximum constraints and demand minimum constraints. We have added the 4 constraints defined in the problem by adding them to the LpProblem  object.

Solve Model

In this step, we will solve the LP problem by calling solve() method. We can print the final value by using the following for loop.

From the above results, we can infer that Warehouse-A supplies the 300 units to Project -2. Warehouse-B supplies 150, 150, and 300 to respective project sites. And finally, Warehouse-C supplies 600 units to Project-3.

In this article, we have learned about Transportation problems, Problem Formulation, and implementation using the python PuLp library. We have solved the transportation problem using a Linear programming problem in Python. Of course, this is just a simple case study, we can add more constraints to it and make it more complicated. In upcoming articles, we will write more on different optimization problems such as transshipment problem, assignment problem, balanced diet problem. You can revise the basics of mathematical concepts in  this article  and learn about Linear Programming  in this article .

  • Solving Cargo Loading Problem using Integer Programming in Python
  • Solving Blending Problem in Python using Gurobi

You May Also Like

problem solving through python programming

Decision Tree Classification in Python

problem solving through python programming

Transshipment Problem in Python Using PuLP

problem solving through python programming

Data Visualization using Pandas

problem solving through python programming

  • Higher Education Textbooks
  • Computer Science

problem solving through python programming

Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet or computer – no Kindle device required .

Read instantly on your browser with Kindle for Web.

Using your mobile phone camera, scan the code below and download the Kindle app.

QR code to download the Kindle App

Image Unavailable

PYTHON PROGRAMMING: USING PROBLEM SOLVING APPROACH

  • To view this video download Flash Player

Follow the author

Reema Thareja

PYTHON PROGRAMMING: USING PROBLEM SOLVING APPROACH Paperback – 10 June 2017

Save extra with 2 offers, 10 days replacement, replacement instructions.

problem solving through python programming

There is a newer edition of this item:

Python Programming | Suitable for Undergraduate Students of Computer Science Engineering, IT and Computer Application | 2nd Edition

Purchase options and add-ons

  • ISBN-10 0199480176
  • ISBN-13 978-0199480173
  • Edition First Edition
  • Publisher Oxford University Press
  • Publication date 10 June 2017
  • Language English
  • Dimensions 17.78 x 2.54 x 23.5 cm
  • Print length 560 pages
  • See all details

Frequently bought together

PYTHON PROGRAMMING: USING PROBLEM SOLVING APPROACH

Customers who viewed this item also viewed

Python Programming | Suitable for Undergraduate Students of Computer Science Engineering, IT and Computer Application | 2nd E

Product description

About the author, product details.

  • Publisher ‏ : ‎ Oxford University Press; First Edition (10 June 2017)
  • Language ‏ : ‎ English
  • Paperback ‏ : ‎ 560 pages
  • ISBN-10 ‏ : ‎ 0199480176
  • ISBN-13 ‏ : ‎ 978-0199480173
  • Item Weight ‏ : ‎ 748 g
  • Dimensions ‏ : ‎ 17.78 x 2.54 x 23.5 cm
  • Country of Origin ‏ : ‎ India
  • #137 in Programming Languages (Books)
  • #838 in Computers & Internet

About the author

Reema thareja.

Discover more of the author’s books, see similar authors, read author blogs and more

Customer reviews

Reviews with images.

Customer Image

  • Sort reviews by Top reviews Most recent Top reviews

Top reviews from India

There was a problem filtering reviews right now. please try again later..

problem solving through python programming

  • Press Releases
  • Amazon Science
  • Sell on Amazon
  • Sell under Amazon Accelerator
  • Protect and Build Your Brand
  • Amazon Global Selling
  • Become an Affiliate
  • Fulfilment by Amazon
  • Advertise Your Products
  • Amazon Pay on Merchants
  • COVID-19 and Amazon
  • Your Account
  • Returns Centre
  • 100% Purchase Protection
  • Amazon App Download
  • Conditions of Use & Sale
  • Privacy Notice
  • Interest-Based Ads

Arduino, Pyserial - Only reading data on first Python Execution

Hello and thanks in advance for the help. My problem is similar to others described on the forum, but these discussions are old, have since become inactive, and a reliable solution to my problem doesn't seem to exist.

I am trying to perform basic serial communication between an Arduino and a Linux machine via USB on the DUE programming port. After connecting the Arduino to my Linux machine, I check to make sure the device exists under 'lsusb' and 'ls /dev/ttyACM*'. Once connected, I run a python script to open the appropriate serial port '/dev/ttyACM1' and I attempt to read data arriving from the Arduino and print it out, line by line, to the terminal. This works perfectly after I first connect my Arduino to the Linux machine.

I then terminate my python script and run it again. Suddenly the data is no longer visible on the Linux side. The device remains connected under 'lsusb' and 'ls /dev/tty*', but attempting to print the arriving data only gives b' '. Ideally, I'd like to resolve this issue for my Arduino DUE, however I have tried other DUEs, and an UNO without resolve.

My minimal code to produce this problem is as follows:

Arduino Side

Basically this code is meant to simple puke data over serial at a set rate of 125 Hz, regardless of whether or not another device is there to read it.

Python/Linux Side

Nothing too crazy here. As mentioned, the python side reads the Arduino's data perfectly after I first connect the Arduino. In the case above python will just print "The message" to terminal repeatedly. But, if I close with 'Ctrl+C' and rerun my python from terminal all I will see is blank lines (or b' ' if I remove the decode part of my readline). I have tried a variety of methods to fix the problem, including placing flush() or reset_input_buffer() in various places. ser.isOpen() always returns 1 when the port is open and 0 after I close the port, regardless of whether its the first time executing the code or the second. in_waiting() returns 0 the second execution as well. I am confident this isn't an issue with baudrate, parity, stopbits, etc., because as mentioned, it works on my first execution of the python code.

In fact, I have a Teensy 4.1 I am using basically in the exact same way and it works fine. Only substantial difference is that it is operating on '/dev/ttyACM0'. I can run and interrupt the receiving side python code for this Teensy as many times as I want without an issue. Another forum suggested there is a bug with pyserial that causes my issue, but seeing that I can get this to work on the Teensy tells me there is something else at play here.

I can also see from watching the lights on my DUE that the device is not power cycling when I interrupt the python side code, so in theory it should still be continuing to dump lines of data over serial despite the fact that the port isn't open with Python. I'd like to get to a point where I can receive the serial data without having to unplug the Arduino every time.

Thanks again for your help.

Related Topics

IMAGES

  1. Problem Solving using Python

    problem solving through python programming

  2. learn problem solving with python

    problem solving through python programming

  3. How to solve a problem in Python

    problem solving through python programming

  4. Programming & Problem Solving Through Python Language (M3-R5)

    problem solving through python programming

  5. problem solving and python programming unit 1

    problem solving through python programming

  6. Python Programming: Using Problem Solving Approach by Reema Thareja-Buy

    problem solving through python programming

VIDEO

  1. GE3151 Problem Solving and Python Programming Apr/May 2023 #r2021 #pspp #sem1 #importantquestions

  2. GE3151 Problem Solving and Python Programming Important 2 Marks Questions for Semester April 2023

  3. Python Problem solving Question #technologies #leetcode #hackerrank #python3 #problemsolving

  4. Algorithmic Problem Solving with Python Ep04

  5. Live on 15th October: Problem Solving [Python Programming]

  6. GE3151|problem solving and Python programming|Easy pass notes|Important questions|2024|Vincent Maths

COMMENTS

  1. Python Practice for Beginners: 15 Hands-On Problems

    Python Practice Problem 1: Average Expenses for Each Semester. John has a list of his monthly expenses from last year: He wants to know his average expenses for each semester. Using a for loop, calculate John's average expenses for the first semester (January to June) and the second semester (July to December).

  2. Python Practice Problems: Get Ready for Your Next Interview

    Python Practice Problem 5: Sudoku Solver. Your final Python practice problem is to solve a sudoku puzzle! Finding a fast and memory-efficient solution to this problem can be quite a challenge. The solution you'll examine has been selected for readability rather than speed, but you're free to optimize your solution as much as you want.

  3. Python Exercises, Practice, Challenges

    Each exercise has 10-20 Questions. The solution is provided for every question. Practice each Exercise in Online Code Editor. These Python programming exercises are suitable for all Python developers. If you are a beginner, you will have a better understanding of Python after solving these exercises. Below is the list of exercises.

  4. Python Exercise with Practice Questions and Solutions

    List of Python Programming Exercises. In the below section, we have gathered chapter-wise Python exercises with solutions. So, scroll down to the relevant topics and try to solve the Python program practice set. Python List Exercises. Python program to interchange first and last elements in a list; Python program to swap two elements in a list

  5. Solve Python

    Join over 23 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews.

  6. Problem Solving in Python

    Step 4 - Solving or Simplification. Once we have laid out the steps to solve the problem, we try to find the solution to the question. If the solution cannot be found, try to simplify the problem instead. The steps to simplify a problem are as follows: Find the core difficulty.

  7. Introduction to Programming with Python

    Click here to Ask AoPS! Introduction to Programming with Python. A first course in computer programming using the Python programming language. This course covers basic programming concepts such as variables, data types, iteration, flow of control, input/output, and functions. 12 lessons.

  8. Problem Solving with Algorithms and Data Structures using Python

    Problem Solving with Algorithms and Data Structures using Python¶. By Brad Miller and David Ranum, Luther College. Assignments; There is a wonderful collection of YouTube videos recorded by Gerry Jenkins to support all of the chapters in this text.

  9. Problem Solving using Python

    Problem Solving using Python - WS 18/19. Programming requires multiple steps, from understanding the problem, designing a solution, coding, testing and debugging it into a running and correct program. Moreover, this program should be easy to understand and consequently modify. Balancing all of these concerns is a challenge for novice programmers.

  10. Learn Problem solving in Python

    Problem solving in Python. Learn problem solving in Python from our online course and tutorial. You will learn basic math, conditionals and step by step logic building to solve problems easily. 4.5 (3278 reviews) 18 lessons Beginner level. 41.6k Learners.

  11. Problem Solving, Python Programming, and Video Games

    This course is an introduction to computer science and programming in Python. Upon successful completion of this course, you will be able to: 1. Take a new computational problem and solve it, using several problem solving techniques including abstraction and problem decomposition. 2. Follow a design creation process that includes: descriptions ...

  12. Python Programming Bootcamp: Learn Python Through Problem Solving

    Learn how to Solve Real Programming Problems with a Focus on Teaching Problem Solving Skills. Understand Python as an Object Oriented and Functional Programming Language. Create GUI Applications using TkInter, Kivy and soon PyQt. Create Applications that Utilize Databases. We will Expand into Algorithms, Django, Flask and Machine Learning.

  13. Programming and Problem Solving Using Python

    Goals. Prime objective is to give students a basic introduction to programming and problem solving with computer language Python. And to introduce students not merely to the coding of computer programs, but to computational thinking, the methodology of computer programming, and the principles of good program design including modularity and encapsulation.

  14. Introduction

    Welcome to the world of problem solving with Python! This first Orientation chapter will help you get started by guiding you through the process of installing Python on your computer. By the end of this chapter, you will be able to: Describe why Python is a useful computer language for problem solvers. Describe applications where Python is used.

  15. Python Basic Exercise for Beginners with Solutions

    This Python essential exercise is to help Python beginners to learn necessary Python skills quickly.. Immerse yourself in the practice of Python's foundational concepts, such as loops, control flow, data types, operators, list, strings, input-output, and built-in functions.

  16. Hands-On Linear Programming: Optimization With Python

    You'll use Python to solve these two problems in the next section. Small Linear Programming Problem. Consider the following linear programming problem: You need to find x and y such that the red, blue, and yellow inequalities, as well as the inequalities x ≥ 0 and y ≥ 0, are satisfied.

  17. Getting Started With Python Programming

    This guide takes you through the process of getting started with programming using the Python programming language. The only language that AoPS teaches (as of May 16, 2021) in a class is Python. The sections flow from one to the next so it's recommended to read through this document in order from top to bottom.

  18. PDF Notes of Lesson Ge3151- Problem Solving and Python Programming

    PROBLEM SOLVING TECHNIQUES Problem solving technique is a set of techniques that helps in providing logic for solving a problem. Problem solving can be expressed in the form of 1. Algorithms. 2. Flowcharts. 3. Pseudo codes. 4. Programs 1.ALGORITHM It is defined as a sequence of instructions that describe a method for solving a problem. In other ...

  19. Python Tutorial

    First, we write a program in a file and run it one time. Second, run a code line by line. Here we provided the latest Python 3 version compiler where you can edit and compile your written code directly with just one click of the RUN Button. So test yourself with Python first exercises. Python3.

  20. Python for loop and if else Exercises [10 Exercise Programs]

    This Python loop exercise include the following: -. It contains 18 programs to solve using if-else statements and looping techniques.; Solutions are provided for all questions and tested on Python 3. This exercise is nothing but an assignment to solve, where you can solve and practice different loop programs and challenges.

  21. Programming, Data Structures And Algorithms Using Python

    Programming, Data Structures And Algorithms Using Python. This course is an introduction to programming and problem solving in Python. It does not assume any prior knowledge of programming. Using some motivating examples, the course quickly builds up basic concepts such as conditionals, loops, functions, lists, strings and tuples.

  22. Programming and Problem Solving using Python

    This textbook is designed to learn python programming from scratch. At the beginning of the book general problem solving concepts such as types of problems, difficulties in problem solving, and problem solving aspects are discussed.From this book, you will start learning the Python programming by knowing about the variables, constants, keywords, data types, indentation and various programming ...

  23. Solving Transportation Problem using Linear Programming in Python

    The transportation problem is a type of Linear Programming problem. In this type of problem, the main objective is to transport goods from source warehouses to various destination locations at minimum cost. In order to solve such problems, we should have demand quantities, supply quantities, and the cost of shipping from source and destination.

  24. PYTHON PROGRAMMING: USING PROBLEM SOLVING APPROACH

    This book will enable students to apply the Python programming concepts in solving real-world problems.The book begins with an introduction to computers, problem solving approaches, programming languages, object oriented programming and Python programming.

  25. Data Science Skills 101: How to Solve Any Problem, Part II

    The first part of this series discussed the growing need for problem-solving skills. As more of our world is automated with AI these skills are more important than ever. This article continues to outline practical strategies for solving any problem. Three more techniques are outlined below with real world examples of their application.

  26. Programming with Generative AI

    There are 3 modules in this course. Our "Programming with Generative AI" course takes you on a practical journey, exploring how generative AI tools can transform your coding workflow. Whether you're a software developer, tech lead, or AI enthusiast, this hands-on program is designed for you. Learn by doing: - Dive deep into GitHub Copilot, the ...

  27. PROBLEM OF THE DAY : 03/06/2024

    Welcome to the daily solving of our PROBLEM OF THE DAY with Saurabh Bansal. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Bit Manipulation but also build up problem-solving skills. Given a number n, find the number of binary strings of length n that contain consecutive 1's in them.

  28. Arduino, Pyserial

    Hello and thanks in advance for the help. My problem is similar to others described on the forum, but these discussions are old, have since become inactive, and a reliable solution to my problem doesn't seem to exist. I am trying to perform basic serial communication between an Arduino and a Linux machine via USB on the DUE programming port. After connecting the Arduino to my Linux machine, I ...

  29. Book not available

    Some alert ... ...