Institute of Computer Science
  1. Courses
  2. 2018/19 fall
  3. Computer Programming (Narva College) (SVNC.00.054)
ET
Log in

Computer Programming (Narva College) 2018/19 fall

  • Home
  • Grading
  • Links

During session 5

slides5.pdf

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 one's first name, last name, e-mail and occupation. The program has to output the information in the 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)

Teacher

5*. 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

4*. Palindrome

A palindrome is a word or phrase which is the same when it is spelled 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.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment