Tag Archives: Python tutorials

Learn Python By Example – while Statement

while Statement Import the random module import random Create a variable of the true number of deaths of an event deaths = 6 Create a variable that is denotes if the while loop should keep running running = True while running is True while running: /* Create a variable that randomly create a integer between …

Learn Python By Example – Selecting Items In A List With Filters

Selecting Items In A List With Filters /* Create an list of items denoting the number of soldiers in each regiment, view the list */ regimentSize = (5345, 6436, 3453, 2352, 5212, 6232, 2124, 3425, 1200, 1000, 1211); regimentSize (5345, 6436, 3453, 2352, 5212, 6232, 2124, 3425, 1200, 1000, 1211) One-line Method This line of …

Learn Python By Example – Mathematical Operations

Mathematical Operations Import the math module import math Display the value of pi. math.pi 3.141592653589793 Display the value of e. math.e 2.718281828459045 Sine, cosine, and tangent math.sin(2 * math.pi / 180) 0.03489949670250097 Exponent 2 ** 4, pow(2, 4) (16, 16) Absolute value abs(-20) 20 Summation sum((1, 2, 3, 4)) 10 Minimum min(3, 9, 10, 12) …