Lab 3 - slcc2c/CS5590_Python GitHub Wiki
- Write a python program to
a. Accept a String from a user and then convert each character in the string to a item in list and tuple.
Print list and tuple.
Sample Input:
welcome
Sample output:
[βwβ, 'e', 'l', 'c', 'o', 'm' ,βeβ]
(βwβ, 'e', 'l', 'c', 'o', 'm',βeβ)
- Write a Python program to
Create a list of tuples.
Sort the list by last element of tuple in increasing order.
Sample input:
List= [(1, 6), (1, 7), (4, 5), (2, 2), (1, 3)]
Sample output:
[(2, 2), (1, 3), (4, 5), (1, 6), (1, 7)]
- Create a Tic Tac Toe game. Assume that Player 1 is X and Player 2 is 0.
I. Create a function to ask for coordinates from each of the player 1 turn by turn. The coordinates will be in the form of βrow,colβ
II. Once user enter the row and col check for whether the cell in the game is already utilized or not. If yes then ask the user again else fill the cell with the respective player sign.
III. Check whether all the cells are utilized by players or not. Stop the process when all cells are full.
IV. Print the game board after each move Suppose initially the game board looks like below:
| | | |
| | | |
| | | |
The computer asks Player 1 (X) what their move is (in the format row,col), and say they type 1,3. Then the game would print out
| | |x |
| | |
|
| | |
|
We will check the winning condition in another assignment to create this game fully.
Hint: Create different functions for each of them
Use split() function of String to parse row, column entered by user
Code can be found here