Institute of Computer Science
  1. Courses
  2. 2022/23 fall
  3. Introduction to Programming (MTAT.03.236)
ET
Log in

Introduction to Programming 2022/23 fall

  • Home
  • Grading
  • Links

During session 1

Exercises

1. Welcome

Write a program that prompts you for your name, and then welcomes you by name. Use input.

Example of the program output:

 Enter your name: Chuck
 Hello Chuck

2. ECTS and hours

Write a program that asks the student about the ECTS and the duration of the present course in weeks. The program outputs the hours per week outlined in this course. (1 ECTS is 26 hours)

Example of the program output:

 Enter ECTS: 3
 Enter weeks: 9
 Hours per week - 8.666666666666666

3. Celsius and Fahrenheit

Write a program which prompts the user for the temperature in Celsius. The program must convert the temperature into the Fahrenheit scale and print it out.

Example of the program output:

 Enter Celcius: 36.6
 Fahrenheit: 97.88000000000001

4. Values and types

Assume that we execute the following assignment statements:

width = 17
height = 12.0

For each of the expressions below, write the value of the expression and the type (of the expression value).

  1. width/2
  2. width/2.0
  3. width/17
  4. width//2
  5. width//2.0
  6. width%2
  7. height/3
  8. 1 + 2 * 5

Use the Python interpreter to check your answers.

5. Shoe size

Write a program that prompts the user for his/her name and actual foot length in cm. The program must compute and output a suitable shoe size (use the following formula: shoe size = 1.5 * (foot length + 1.5)). Round the answer (you can use round for that, e.g. round(2.5) will give 3).

 Enter your name: Marina
 Enter your foot length (cm): 23.5
 Dear Marina, your suitable shoe size is 38

Homework 1

The deadline is Friday, the 9th of September, 23:59 (Estonian time).

You have decided to visit the United States of America. On your first day, you hear people talking about how tall they are in feet, and all the things are weighed in pounds. You soon realize that they use the imperial system instead of the metric system like most of Europe.

Write a program that

  • asks the user for the user's name, height in centimeters, and weight in kilograms, and
  • calculates and outputs the height in feet and weight in pounds. Use the following ratios for your calculations: 1 cm = 0.0328 ft and 1 kg = 2.20 lb. Round the answer to 1 decimal (you can use round for that, e.g. round(2.55,1) will give 2.6).

Example:

>>> %Run solution.py
Enter your name: Chuck
Enter your height in cm: 180
Enter your weight in kg: 80
Hi Chuck, your height is 5.9 ft and weight 176.0 lb

If you have been struggling with this exercise for some time, maybe you can get help from troubleshooter: https://progtugi.cs.ut.ee/#/ts/62024a756449631d0c385dce/. It tries to explain the most common problems and give hints.

At the end of the session go to Moodle and submit all programs written during the session.

  • 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