|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>My Learning Website</title>
|
|
|
|
<link href="/styles/styles.css" rel="stylesheet" type="text/css">
|
|
|
|
<link href="/programming/styles/styles.css" rel="stylesheet" type="text/css">
|
|
|
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
|
|
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
|
|
|
<!--[if lt IE 9]>
|
|
|
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
|
|
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
|
|
|
<![endif]-->
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div class="banner">
|
|
|
|
<h1 class="courselink">Python Essential Traning</h1>
|
|
|
|
<h2 class="lecturer">LinkedIn Learning : Bill Weinman</h2>
|
|
|
|
<h2 class="episodetitle">Code Sample</h2>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<article>
|
|
|
|
<h2 class="sectiontitle">List Primes</h2>
|
|
|
|
<pre class="inset">
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2009-2017 BHG http://bw.org/
|
|
|
|
|
|
|
|
def isprime(n):
|
|
|
|
if n <= 1:
|
|
|
|
return False
|
|
|
|
for x in range(2, n):
|
|
|
|
if n % x == 0:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def listprimes():
|
|
|
|
for n in range(100):
|
|
|
|
if isprime(n):
|
|
|
|
print(n, end=' ', flush=True)
|
|
|
|
|
|
|
|
n = 5
|
|
|
|
if isprime(n):
|
|
|
|
print(f'{n} is prime')
|
|
|
|
else:
|
|
|
|
print(f'{n} not prime')
|
|
|
|
|
|
|
|
listprimes()</pre>
|
|
|
|
</article>
|
|
|
|
|
|
|
|
<div class="btngroup">
|
|
|
|
<button class="button" onclick="window.location.href='classes.html';">
|
|
|
|
Previous Chapter - Classes
|
|
|
|
</button>
|
|
|
|
<button class="button" onclick="window.location.href='string.html';">
|
|
|
|
Next Chapter - String Objects
|
|
|
|
</button>
|
|
|
|
<button class="button" onclick="window.location.href='/programming/pythonessentialtraining/pythonessentialtraining.html'">
|
|
|
|
Course Contents
|
|
|
|
</button>
|
|
|
|
<button class="button" onclick="window.location.href='/programming/programming.html'">
|
|
|
|
Programming Page
|
|
|
|
</button>
|
|
|
|
<button class="button" onclick="window.location.href='/index.html'">
|
|
|
|
Home
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|