# Category: Python Programming Practice

python tutorials and learn python

### 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…

### 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…

### 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…

### Python Programming Practice-Flag variables

Python Programming Practice-Flag variables A ﬂag 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…

### 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…

### 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…

### 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…

### 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 ﬂoating point num- bers. The important thing to remember about them is you typically only…