Homework 5
The deadline is Thursday, the 6th of October, 23:59 (Estonian time).
Homework 5.1 Chess piece moves
In chess notation short piece names are used, for example, K = king, Q = queen, N = knight etc. and each move of a piece is indicated by the piece's uppercase letter, plus the coordinate of the destination square in lowercase. For example, Be5 (bishop moves to e5), Nf3 (knight moves to f3). For pawn moves, a letter indicating pawn is not used, only the destination square is given. For example, c5 (pawn moves to c5).
Write a function named chessMoves
that finds the number of moves made in a chess game with a specific chess piece (excluding pawn). The function should take 2 strings as arguments, the first one is all the chess moves separated by a space character and the second one is the piece for which the number of moves will be returned. The function should find the number of moves made with the selected piece and return it. The program should print out the selected piece and how many moves were made with it. The piece for function argument should be received through user input.
Example function call:
>>>chessMoves("e4 e5 Qh5 Nc6 Bc4 Nf6 Qf7", "N") 2
Example of the program output:
>>> %Run solution.py
Please select a chess piece: N
There were 2 moves made with N.
If you have been struggling with this exercise for some time, maybe you can get help from troubleshooter: https://progtugi.cs.ut.ee#/ts/623ade52ef7eaf5634394a42/
. It tries to explain the most common problems and give hints.
Homework 5.2 String correction
A cat ran over your keyboard and your string got messed up. Luckily it only ran over all numerical keys. Write a program that removes all the numbers from the string and capitalizes the first letter of each word and returns the result.
Hint: You can use isnumeric()
to check if a character is a number or not and title()
to capitalize every word.
Example:
>>> %Run solution.py
13H3e1llo0 312w20orl3d!432
Hello World!
If you have been struggling with this exercise for some time, maybe you can get help from troubleshooter: https://progtugi.cs.ut.ee#/ts/623ae19def7eaf5634394a71/
. It tries to explain the most common problems and give hints.
Go to Moodle and upload your solution into Homework 5.