Reference no: EM132366616
Purpose of the assessment (with ULO Mapping)
Assess student's ability to develop algorithmic solutions to programming problems using Python language.
Individual Assignment Specifications
Purpose:
This assignment evaluates your understanding of basic programming principles using Python language. In particular, it assesses your ability to develop algorithms to solve simple problems, successfully run python programs, and your ability to write meaningful comments when required.
1. You may have noticed that some English words can be read both ways (from left to right or right to left). For example, Kayak, Racecar and Madam can all be read both ways. Most words however can only be read from left to right, for example, Melbourne, Python and Holmes. Write a program (name it, checkWord.py) that finds out if a given word can be read both ways. The program prompts the user to enter a word, and then either prints "Both ways" or "One way" as an output.
For example:
If the input word is: "Kayak" The output would be: Both ways
If the input word is: "Holmes" The output would be: One way
Hint:
• Start by prompting the user for a word
• Convert the word into small letters
• Write the rest of the program
2. Write a program (name it, unique.py) that takes a text message as an input and prints out the same message, however with unique words only. In other words, all words repeated within the text must only appear once. You need to remove all punctuation marks from the returned message. Punctuation marks include ". , ; : ? !"
For example:
If the input message is: "You're an insomniac, you tell yourself: there are profound truths revealed only to the insomniac by night like those phosphorescent minerals veined and glimmering in the dark but coarse and ordinary otherwise; you have to examine such minerals in the absence of light to discover their beauty, you tell yourself."
The output message would be: "you're an insomniac you tell yourself there are profound truths revealed only to the by night like those phosphorescent minerals veined and glimmering in dark but coarse ordinary otherwise have examine such absence of light discover their beauty"
Hint:
• Use the message in the example as a test case. Store it in a variable called text.
• You will need to convert the message into small case letters, and remove punctuation marks.
• Your final output must be similar to the output in the example above.
3. Three pets live in a happy house: dog, cat and a mouse. The dog often chases the cat, the cat likes to chase the mouse, however the mighty dog runs away when it sees the mouse. Develop a game (let's call it happyHouse.py) which can be played by two players. The program asks the two players (player1 and player2) to choose either 1 for dog, 2 for cat, or 3 for mouse. The rules for this game are simple:
The dog prevails over the cat The cat prevails over the mouse The mouse prevails over the dog
So if player1 chooses a dog and player2 chooses a cat, player1 wins. If player1 chooses a dog and player2 chooses a mouse, player2 wins, and so forth. If both players choose the same pet, then the result will be draw. The players continue playing until either player hits enter without choosing a number (1, 2 or 3). Each time the game is run, the result is printed on the screen (for example, Player 1 wins or Player 2 wins).
Hint:
• Define an indefinite loop which only breaks when either player enters an empty string (hits enter with no entry).
• Within the loop, prompt Player 1 and Player 2 to enter 1 for dog, 2 for cat or 3 for mouse
• Based on the choices made by Player 1 and Player 2, your program prints out the appropriate message, which can either be "draw", "Player 1 wins" or "Player 2 wins".