Chapter 1: Excercises

This page contains a set of excercises for the corresponding chapter.
Read the task description, copy the code template if present and solve it in your Eclipse.
If you are stuck, you can show the solution for this task. Be careful not to spoil the solution for yourself unnecessarily.

Contents

  1. Swap Variable Values
  2. Speeder
  3. User Interaction
  4. Circle Area
  5. House


  1. Swap Variable Values
  2. Your task is to implement an algorithm which swaps the value of two variables.
    Do not just change the values in the code.
    You can implement this algorithm by using a temporary variable.
    Also, you can do it without a third variable using arithmetic operators.

    If initially a is 42 and b is 5, after the execution a should be 5 and b should be 42

    Back to top



  3. Speeder
  4. This is a physics textbook excercise.

    At the place of a traffic accident, the police determines that the braking distance of a car is 19.0 meters.
    The coefficient of friction of the tire material on the road surface is μ = 0,75.

    What was the speed of the driver?

    The required formula:

    Back to top



  5. User Interaction
  6. Your task is to implement a simple user interaction.
    The machine should first ask the user what is his or her name.
    Then, the machine should greet the user and ask the users age.
    Finally, the machine should compute the birth year of the user.
    Just use the current year as a number, you cannot query the current date from your machine using MuLE.

    The entire interaction could look like this:

    Back to top



  7. Circle Area
  8. Your task is to calculate the area of a circle: A = π * r2

    Start by declaring the necessary variables: radius, pi and area.

    Set radius to 2 and pi top 3.14 and compute and print the area value.
    Using these values, the result should be 12.56.

    Back to top



  9. House
  10. This is basically a kids game.
    Your task is to draw a house using the Turtle library in one go, i.e. without jumping to other locations while drawing.

    The variable l_a represents the length of the horizontal and vertical lines.
    l_b is the length of the diagonal lines in the house, you have to compute it, for example by using Pythagoras.
    l_c is the length of the diagonal lines on the roof, you also have to compute it.

    Back to top