Category: Python Programming Practice

python tutorials and learn python

Created with Sketch.

Python program to solve quadratic equation

Python program to solve quadratic equation Quadratic equation: Quadratic equation is made from a Latin term “quadrates” which means square. It is a special type of equation having the form of: ax2+bx+c=0 Here, “x” is unknown which you have to find and “a”, “b”, “c” specifies the numbers such that “a” is not equal to…
Read more

Python Programming Practice-Strings

 Python Programming Practice-Strings Strings are a data type in Python for dealing with text. Python has a number of powerful features for manipulating strings.  Basics Creating a string A string is created by enclosing text in quotes. You can use either single quotes, ‘ , or double quotes, ” . A triple-quote can be used…
Read more

Python Programming Practice-example programs

Python Programming Practice-example programs It is a valuable skill is to be able to read code. In this section we will look in depth at some simple programs and try to understand how they work. Example 1 The following program prints Hello a random number of times between 5 and 25. from random import randint…
Read more

Python Programming Practice-Flag variables

Python Programming Practice-Flag variables A flag variable can be used to let one part of your program know when something happens in another part of the program. Here is an example that determines if a number is prime. num = eval ( input ( ‘ Enter number: ‘ )) flag = 0 for i in…
Read more

Python Programming Practice-SWAPPING

Python Programming Practice-SWAPPING Example 1 This program will add up the numbers from 1 to 100. The way this works is that each time we encounter a new number, we add it to our running total, s . s = 0 for i in range (1,101): s = s + i print ( ‘ The…
Read more

Python Programming Practice-Miscellaneous Topics I

Python Programming Practice-Miscellaneous Topics I    Counting Very often we want our programs to count how many times something happens. For instance, a video game may need to keep track of how many turns a player has used, or a math program may want to count how many numbers have a special property. The key…
Read more

If statements

If statements Quite often in programs we only want to do something provided something else is true. Python’s if statement is what we need.  A Simple Example Let’s try a guess-a-number program. The computer picks a random number, the player tries to guess, and the program tells them if they are correct. To see if…
Read more

Numbers

Numbers This chapter focuses on numbers and simple mathematics in Python.  Integers and Decimal Numbers Because of the way computer chips are designed, integers and decimal numbers are represented differently on computers. Decimal numbers are represented by what are called floating point num- bers. The important thing to remember about them is you typically only…
Read more

Python Programming Practice-For loops

Probably the most powerful thing about computers is that they can repeat things over and over very quickly. There are several ways to repeat things in Python, the most common of which is the for loop.   Example 1 The following program will print Hello ten times: for i in range (10): print ( ‘…
Read more

Python Programming Practice-Optional arguments

Python Programming Practice-Optional arguments There are two optional arguments to the print function. They are not overly important at this stage of the game, so you can safely skip over this section, but they are useful for making your output look nice. sep Python will insert a space between each of the arguments of the…
Read more