Programming Exercises

P1:

Write a Python program that prompts the user for a list of integers, stores in another list only those values between 1–100, and displays the resulting list.

Solution:


In [ ]:

P2:

Write a Python program that prompts the user for a list of integers, stores in another list only those values that are in tuple valid_values, and displays the resulting list.

Solution:


In [ ]:

P3:

Write a Python program that prompts the user for a list of integers and stores them in a list. For all values that are greater than 100, the string 'over' should be stored instead. The program should display the resulting list.

Solution:


In [ ]:

P4:

Write a Python program that prompts the user to enter a list of first names and stores them in a list. The program should display how many times the letter 'a' appears within the list.

Solution:


In [ ]:

P5:

Write a Python program that prompts the user to enter a list of words and stores in a list only those words whose first letter occurs again within the word (for example, 'Baboon'). The program should display the resulting list.

Solution:


In [ ]:

P6:

Write a Python program that prompts the user to enter integer values for each of two lists. It then should displays whether the lists are of the same length, whether the elements in each list sum to the same value, and whether there are any values that occur in both lists.

Solutions:


In [ ]:

Development Problems

D1: Morse Code Encryption/Decryption Program

Develop and test a Python program that allows a user to type in a message and have it converted into Morse code, and also enter Morse code and have it converted back to the original message. The encoding of Morse code is given below.

Format the original message (containing English words) so that there is one sentence per line. Format the Morse code file (containing dots and dashes) so that there is one letter per line, with a blank line following the last letter of each word, and two blank lines following the end of each sentence (except the last).

Solution: