During session 5
Exercises
1. Word Square
Write a program that asks a word from the user and then outputs a “square” of this word in the upper case.
For example, if the user enters "Hello", then the output is
HELLO HELLO HELLO HELLO HELLO
And if the input is "cat", the output is
CAT CAT CAT
First, try to solve this exercise using a loop. After that try to solve this exercise without the loop (newline symbol in Python is '\n').
Hint:
>>>len("cat")
3
>>>"cat".upper()
CAT
>>>"cat" * 3
catcatcat
2. Gender from an Estonian Personal Identifications Number
Write a program which prompts the user for the Estonian Personal Identification Number, finds and prints out one's gender from the entered code. Reminder: the form of the Estonian Personal Identification Number is GYYMMDDSSSC, where G shows gender (odd numbers for a male, even numbers for a female).
3. Business card
Write a program that prompts the user for his first name, last name, e-mail and occupation. The program has to output the information in a frame around the text.
Here is an example of the program output:
Please enter your first name: Malle Please enter your last name: Mets Please enter your e-mail: malle@ut.ee Please enter your occupation: Teacher +------------------------------------+ | | | Malle Mets - malle@ut.ee | | | | Teacher | | | +------------------------------------+
Hint:
>>>"-"*20
------------------
>>>"Teacher".center(30)
4*. Euros and cents
Write a program which prompts the user for the number of cents and prints out the same amount in euros and cents or only in euros or only in cents. For example:
- if the user enters 207, the output is "2 euros and 7 cents"
- if the user enters 101, the output is "1 euro and 1 cent" (NB! not "1 euros and 1 cents", the singular and the plural must be distinguished)
- if the user enters 95, the output is "95 cents" (without euros)
- if the user enters 100, the output is "1 euro" (without cents)
Hint:
- // truncated division
- % remainder
5*. Palindrome
A palindrome is a word or phrase which is the same when you spell it backwards, e.g. ‘deed’ or ‘level’.
Write a program which prompts the user for a word, checks and prints out whether this word is palindrome or not.
At the end of the session go to Moodle and submit all programs written during the session.