Google

Python warmup exercises

Written on:November 14, 2012
Comments
Add One

Programming problems I am using as warmup exercises in my Python programming class. The key is to give them some simple problems they can solve so as not to discourage them, at the same time giving them more difficult problems to challenge them.

1. Write a program that will ask the user for a number between 1 and 20, then print a line of * of that length. Example:

Enter a number: 6

* * * * * *

2. Write a program that will ask the user for five numbers between 1 and 20 (inclusive). Print the numbers as horizontal bar charts using the * character. Example:

Enter a number: 5
Enter a number: 10
Enter a number: 5
Enter a number: 15
Enter a number: 20

* * * * *
* * * * * * * * * *
* * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *

3. Write a program that will ask the user for a number between 1 and 20, then print a four-sided figure whose every sides is made of * equal to the number. Example:

Enter a number: 5

* * * * *
*       *
*       *
*       *
* * * * *

4. Write a program that will ask the user for five numbers between 1 and 20 (inclusive). Print the numbers as vertical bar charts using the * character. The height of the highest bar should be equal to the highest number in the set. Example:

Enter a number: 5
Enter a number: 10
Enter a number: 5
Enter a number: 15
Enter a number: 20


        *
        *
        *
        *
        *
      * *
      * *
      * *
      * *
      * *
  *   * *
  *   * *
  *   * *
  *   * *
  *   * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

5. Write a program that will display the multiplication tables for the numbers 1 to 10 in this format:

1 x 1 = 1     2 x 1 = 2     3 x 1 = 3     4 x 1 = 4     5 x 1 = 5
1 x 2 = 2     2 x 2 = 4     3 x 2 = 6     4 x 2 = 8     5 x 2 = 10
                               :
                               :

6 x 1 = 6     7 x 1 = 7     8 x 1 = 8     9 x 1 = 9     10 x 1 = 10
6 x 2 = 12    7 x 2 = 14    8 x 3 = 24    9 x 2 = 18    10 x 2 = 20
                               :
                               :

Use loops, okay? Don’t hardcode the output.

6. Write a program that will print a calendar. The program will ask what day the 1st of the month falls in (0 = “Sunday”, 2 = “Monday”, 3 = “Tuesday”…) and how many days there are in this month. Example output:

What day is the first of the month? 0
How many days for this month? 30

S  M  T  W  T  F  S
1  2  3  4  5  6  7
8  9  10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

Leave a Comment

Your email address will not be published. Required fields are marked *

Skip to toolbar