def reverse(l)
that
reverses a list in place (using the same memory as the list itself and
swapping elements). Note that this method will not return any value. Write a
program (main) that prompts the user to enter a list of numbers, invokes the
reversal function, and then displays the result.
ch10_pr10.py
.python3 ch10_pr10.py
on MAC and
py -3 ch10_pr10.py
on Windows)
user provides input (red):
Enter a list of numbers: 2 5 3 7 6
The numbers reversed are: 6 7 3 5 2
ch13_pr05.py
.python3 ch13_pr05.py
on MAC and
py -3 ch13_pr05.py
on Windows)
user provides input (red),
input file can be
downloaded/seen here:
Enter a filename: story.txt
Enter a string to be replaced: pig
Enter the new string to replace the old string: dog
Done
output file contents can be
seen here
# Compute the distance of two points
def distance(p1, p2)
# Compute the indices of the two nearests points
def nearestPoints(points)
points = [[-1, 0, 3], [-1, -1, -1], [4, 1, 1], [2, 0.5, 9], [3.5, 2, -1], [3, 1.5, 3], [-1.5, 4, 2], [5.5, 4, -0.5]]
ch11_pr07.py
.python3 ch11_pr07.py
on MAC and
py -3 ch11_pr07.py
on Windows)
user provides input (red):
Considering the following points:
[[-1, 0, 3], [-1, -1, -1], [4, 1, 1], [2, 0.5, 9], [3.5, 2, -1], [3, 1.5, 3], [-1.5, 4, 2], [5.5, 4, -0.5]]
The nearest points are: [4, 1, 1] and [3.5, 2, -1]
m1
and m2
are identical
if they have the same contents. Write a function
def equals(m1, m2)
that returns True
if
m1
and m2
are identical. Write a test program
(main) that prompts the user for two lists of integers and displays whether
the two are identical.
ch11_pr29.py
.python3 ch11_pr29.py
on MAC and
py -3 ch11_pr29.py
on Windows)
user provides input (red):
Enter m1: 51 25 22 6 1 4 24 54 6
Enter m2: 51 22 25 6 1 4 24 54 6
The two lists are identical
python3 ch11_pr29.py
on MAC and
py -3 ch11_pr29.py
on Windows)
user provides input (red):
Enter m1: 51 5 22 6 1 4 24 54 6
Enter m2: 51 22 25 6 1 4 24 54 6
The two lists are not identical
TicTacToe
with a public function play
(and as many
private data fields and methods as you need) for playing tic-tac-toe. Your
main program should create an instance and play the game. The user will
enter a row and column to place their token. Protect against bad user input
[(bad row/column less than 0 or greater than 2) and (already taken space)].
Report reasonable messages for errors and allow the user to try again.
Report a reasonable end game message.
tictactoe.py
and
ch11_pr09.py
.python3 ch11_pr09.py
on MAC and
py -3 ch11_pr09.py
on Windows)
user provides input (red):
-------------
| | | |
-------------
| | | |
-------------
| | | |
-------------
Enter a row (0, 1, or 2) for player X: 0
Enter a column (0, 1, or 2) for player X: 0
-------------
| X | | |
-------------
| | | |
-------------
| | | |
-------------
Enter a row (0, 1, or 2) for player O: 1
Enter a column (0, 1, or 2) for player O: 4
Invalid space, retry
Enter a row (0, 1, or 2) for player O: 1
Enter a column (0, 1, or 2) for player O: 1
...
-------------
| X | O | X |
-------------
| | O | X |
-------------
| O | | X |
-------------
X player won