Brightest Diwali Sale! Get an Extra 10% OFF , Use Code: FEST10
Lifetime Access
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 a beginner's course that helps you to understand Python programming language from scratch.
This course has a 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 a very lucid and detailed way
when you complete our course, you will be an expert in python
Much useful for SPPU students struggling with PPS subjects without having any knowledge of computer science
You can build your own logic to answer every question in an exam without mugging up answers from textbooks
The prime objective is to give students a basic introduction to programming and problem-solving with the 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 the basics, features, and future of Python programming.
- To acquaint myself with data types, input-output statements, decision-making, looping, and functions in Python
- To learn features of Object Oriented Programming using Python
- To acquaint myself with the use and benefits of file handling in Python
Prerequisites
No programming or knowledge of computers needed. You will learn everything you need to know
Check out the detailed breakdown of what’s inside the course
Instructor Details
Course Certificate
Use your certificate to make a career change or to advance in your current career.
Our students work with the Best
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
Online Certifications
Master prominent technologies at full length and become a valued certified professional.
1800-202-0515
- Python Basics
- Interview Questions
- Python Quiz
- Popular Packages
- Python Projects
- Practice Python
- AI With Python
- Learn Python3
- Python Automation
- Python Web Dev
- DSA with Python
- Python OOPs
- Dictionaries
Intermediate Coding Problems in Python
Python, being a very dynamic and versatile programming language, is used in almost every field. From software development to machine learning, it covers them all. This article will focus on some interesting coding problems which can be used to sharpen our skills a bit more and at the same time, have fun solving this list of specially curated problems. Although this article will focus on solving these problems using Python, one can feel free to use any other language of their choice. So let’s head right into it!
Infinite Monkey Theorem
The theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type a given text, such as the complete works of William Shakespeare. Well, suppose we replace a monkey with a Python function. How long would it take for a Python function to generate just one sentence? The sentence we will go for is: “a computer science portal for geeks”. The way we will simulate this is to write a function that generates a string that is 35 characters long by choosing random letters from the 26 letters in the alphabet plus space. We will write another function that will score each generated string by comparing the randomly generated string to the goal. A third function will repeatedly call generate and score, then if 100% of the letters are correct we are done. If the letters are not correct then we will generate a whole new string. To make it easier to follow, our program should keep track of the best string generated so far.
Example:
Here, we wrote three functions. One will generate a random string using the 26 characters of the alphabet and space. The second function will then score the generated string by comparing each letter of it with the goalString. The third function will repeatedly call the first two functions until the task is completed. It will also take note of the best string generated so far by comparing their scores. The one with the highest score will be the best one. Finally, we run this program in our IDE and see it work.
The substring dilemma
This is a really interesting program as it generates some really funny outputs. It is also a healthy practice problem for beginners who want to understand the “string” type more clearly. Let’s look into the problem. Given a string, find a substring based on the following conditions:
- The substring must be the longest one of all the possible substring in the given string.
- There must not be any repeating characters in the substring.
- If there is more than one substring satisfying the above two conditions, then print the substring which occurs first.
- If there is no substring satisfying all the aforementioned conditions then print -1.
Although there can be many methods of approach to this problem, we will look at the most basic one.
Here, we write a single function that will carry out the entire task. First it will initialize variables called substring and testList to store the substring and a list of possible outputs respectively. Then it will loop over the entire string provided and break every time it finds a repetition and appends that word to testList. Finally, the longest word out of the possible outputs is returned.
Output:
A low-level implementation of the classic game “Mastermind”. We need to write a program that generates a four-digit random code and the user needs to guess the code in 10 tries or less. If any digit out of the guessed four-digit code is wrong, the computer should print out “B”. If the digit is correct but at the wrong place, the computer should print “Y”. If both the digit and position is correct, the computer should print “R”. Example:
First, we write a function to generate a random four-digit code using Python’s random module. Next, we define a function that asks for user input. Finally, we write a function that compares the generated code to the guessed code and gives appropriate results.
Direction Catastrophe
A very simple problem with many different solutions, but the main aim is to solve it in the most efficient way. A man was given directions to go from point A to point B. The directions were: “SOUTH”, “NORTH”, “WEST”, “EAST”. Clearly “NORTH” and “SOUTH” are opposite, “WEST” and “EAST” too. Going to one direction and coming back in the opposite direction is a waste of time and energy. So, we need to help the man by writing a program that will eliminate the useless steps and will contain only the necessary directions. For example: The directions [“NORTH”, “SOUTH”, “SOUTH”, “EAST”, “WEST”, “NORTH”, “WEST”] should be reduced to [“WEST”]. This is because going “NORTH” and then immediately “SOUTH” means coming back to the same place. So we cancel them and we have [“SOUTH”, “EAST”, “WEST”, “NORTH”, “WEST”]. Next, we go “SOUTH”, take “EAST” and then immediately take “WEST”, which again means coming back to the same point. Hence we cancel “EAST” and “WEST” to giving us [“SOUTH”, “NORTH”, “WEST”]. It’s clear that “SOUTH” and “NORTH” are opposites hence canceled and finally we are left with [“WEST”].
In the above solution, we create a dictionary of opposites to help us determine if a given direction is opposite to the other. Next, we initialize a variable called finalDirections which will be our output. If the direction which is in the givenDirections is opposite of the last element in finalDirections, we pop it out of finalDirections otherwise we append it to finalDirections.
Comparing arrays
This problem helps one to understand the key concepts of an array(list) in Python. Two arrays are said to be the same if they contain the same elements and in the same order. However, in this problem, we will compare two arrays to see if they are same, but with a slight twist. Here, two arrays are the same if the elements of one array are squares of elements of other arrays and regardless of the order. Consider two arrays a and b .
a = [121, 144, 19, 161, 19, 144, 19, 11] b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]
Here b can be written as:
b = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]
which is a square of every element of a . Hence, they are same. If a or b are None, our program should written False
Similar Reads
- Python Programs
- python-basics
Please Login to comment...
Improve your coding skills with practice.
IMAGES
VIDEO
COMMENTS
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.
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 a …
First, we write a function to generate a random four-digit code using Python’s random module. Next, we define a function that asks for user input. Finally, we write a function that compares the generated code to the …
This Python loop exercise contains 18 different loop programs and challenges to solve if-else conditions, for loops, range() functions, and while loops. Solutions are provided for …