Commit a4aeb336 authored by Julin S's avatar Julin S Committed by Raymond Hettinger

bpo-38539: Update demo files (GH-16890)

parent 20bf8e08
This directory contains a collection of demonstration scripts for This directory contains a collection of demonstration scripts for
various aspects of Python programming. various aspects of Python programming.
beer.py Well-known programming example: Bottles of beer. beer.py Well-known programming example: Bottles of beer.
eiffel.py Python advanced magic: A metaclass for Eiffel post/preconditions. eiffel.py Python advanced magic: A metaclass for Eiffel post/preconditions.
hanoi.py Well-known programming example: Towers of Hanoi. hanoi.py Well-known programming example: Towers of Hanoi.
life.py Curses programming: Simple game-of-life. life.py Curses programming: Simple game-of-life.
markov.py Algorithms: Markov chain simulation. markov.py Algorithms: Markov chain simulation.
mcast.py Network programming: Send and receive UDP multicast packets. mcast.py Network programming: Send and receive UDP multicast packets.
queens.py Well-known programming example: N-Queens problem. queens.py Well-known programming example: N-Queens problem.
redemo.py Regular Expressions: GUI script to test regexes. redemo.py Regular Expressions: GUI script to test regexes.
rpython.py Network programming: Small client for remote code execution. rpython.py Network programming: Small client for remote code execution.
rpythond.py Network programming: Small server for remote code execution. rpythond.py Network programming: Small server for remote code execution.
sortvisu.py GUI programming: Visualization of different sort algorithms. sortvisu.py GUI programming: Visualization of different sort algorithms.
ss1.py GUI/Application programming: A simple spreadsheet application. spreadsheet.py GUI/Application programming: A simple spreadsheet application.
vector.py Python basics: A vector class with demonstrating special methods. vector.py Python basics: A vector class demonstrating special methods.
\ No newline at end of file
...@@ -27,7 +27,7 @@ def hanoi(n, a, b, c, report): ...@@ -27,7 +27,7 @@ def hanoi(n, a, b, c, report):
class Tkhanoi: class Tkhanoi:
# Create our objects # Create our objects
def __init__(self, n, bitmap = None): def __init__(self, n, bitmap=None):
self.n = n self.n = n
self.tk = tk = Tk() self.tk = tk = Tk()
self.canvas = c = Canvas(tk) self.canvas = c = Canvas(tk)
...@@ -77,7 +77,7 @@ class Tkhanoi: ...@@ -77,7 +77,7 @@ class Tkhanoi:
# Run -- never returns # Run -- never returns
def run(self): def run(self):
while 1: while True:
hanoi(self.n, 0, 1, 2, self.report) hanoi(self.n, 0, 1, 2, self.report)
hanoi(self.n, 1, 2, 0, self.report) hanoi(self.n, 1, 2, 0, self.report)
hanoi(self.n, 2, 0, 1, self.report) hanoi(self.n, 2, 0, 1, self.report)
...@@ -94,7 +94,7 @@ class Tkhanoi: ...@@ -94,7 +94,7 @@ class Tkhanoi:
# Lift the piece above peg a # Lift the piece above peg a
ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a]) ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a])
while 1: while True:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
if y2 < ay1: break if y2 < ay1: break
c.move(p, 0, -1) c.move(p, 0, -1)
...@@ -103,7 +103,7 @@ class Tkhanoi: ...@@ -103,7 +103,7 @@ class Tkhanoi:
# Move it towards peg b # Move it towards peg b
bx1, by1, bx2, by2 = c.bbox(self.pegs[b]) bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
newcenter = (bx1+bx2)//2 newcenter = (bx1+bx2)//2
while 1: while True:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
center = (x1+x2)//2 center = (x1+x2)//2
if center == newcenter: break if center == newcenter: break
...@@ -114,7 +114,7 @@ class Tkhanoi: ...@@ -114,7 +114,7 @@ class Tkhanoi:
# Move it down on top of the previous piece # Move it down on top of the previous piece
pieceheight = y2-y1 pieceheight = y2-y1
newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2 newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2
while 1: while True:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
if y2 >= newbottom: break if y2 >= newbottom: break
c.move(p, 0, 1) c.move(p, 0, 1)
......
...@@ -29,7 +29,7 @@ def main(): ...@@ -29,7 +29,7 @@ def main():
with conn: with conn:
print('connection from', remotehost, remoteport) print('connection from', remotehost, remoteport)
request = b'' request = b''
while 1: while True:
data = conn.recv(BUFSIZE) data = conn.recv(BUFSIZE)
if not data: if not data:
break break
......
...@@ -444,7 +444,7 @@ def quicksort(array): ...@@ -444,7 +444,7 @@ def quicksort(array):
array.wait(1000) array.wait(1000)
left = first left = first
right = last right = last
while 1: while True:
array.message("Sweep right pointer") array.message("Sweep right pointer")
right = right-1 right = right-1
array.show_right(right) array.show_right(right)
...@@ -473,7 +473,7 @@ def quicksort(array): ...@@ -473,7 +473,7 @@ def quicksort(array):
array.hide_partition() array.hide_partition()
def demosort(array): def demosort(array):
while 1: while True:
for alg in [quicksort, insertionsort, selectionsort, bubblesort]: for alg in [quicksort, insertionsort, selectionsort, bubblesort]:
randomize(array) randomize(array)
alg(array) alg(array)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment