Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Exercises πŸ‹οΈβ€β™‚οΈ

Here are the exercises for the Python Basics module. These exercises are designed to test your understanding of the concepts covered in the module. You can use the exercises to practice and improve your Python skills.

Covered Topics:

  • Simple Input/Output in a loop
  • Break and Continue
  • Nested Loops
  • Conditional Statements
  • Loops

Exercise 1: Countdown Timer - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program timer that asks the user for the number of seconds n to start the countdown from.

Input:

  • An integer representing the number of seconds to start the countdown from.

Output:

  • A countdown from n to 1, followed by the message "Start!".

Examples:

No. Inputs Outputs
1 5 5
4
3
2
1
Start!
2 3 3
2
1
Start!
3 1 1
Start!

Note:

The problem tests the ability to use loops and conditional statements to implement a countdown timer.

Exercise 2: M Times N - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program that asks the user for two numbers n and m and prints the number n m times in a row.

Input:

  • Two integers representing the numbers n and m.

Output:

  • The number n printed m times in a row.

Examples:

No. Inputs Outputs
1 10
5
10 10 10 10 10
2 3
3
3 3 3
3 7
1
7

Note:

The problem tests the ability to use loops and conditional statements to print a number multiple times.

Exercise 3: Sequence of Integers - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to output all integers from 20 to n inclusive (where n > 20), where n is an integer entered by the user.

Input:

  • An integer representing the upper limit of the range.

Output:

  • A sequence of integers from 20 to n inclusive.

Examples:

No. Inputs Outputs
1 25 20 21 22 23 24 25
2 30 20 21 22 23 24 25 26 27 28 29 30
3 37 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
4 20 20

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 4: Number of # Characters - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to print integers from 1 to n with the number of # characters equal to the value of the number.

Input:

  • An integer representing the upper limit of the range.

Output:

  • A sequence of integers from 1 to n inclusive, with the number of # characters equal to the value of the number.

Examples:

No. Inputs Outputs
1 5 1 #
2 ##
3 ###
4 ####
5 #####
2 3 1 #
2 ##
3 ###
3 7 1 #
2 ##
3 ###
4 ####
5 #####
6 ######
7 #######

Note:

The problem tests the ability to use conditional statements to classify an input into one of several categories.

Exercise 5: Sum of Integers - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to calculate the sum of all integers from 1 to n inclusive.

Input:

  • An integer representing the upper limit of the range.

Output:

  • An integer representing the sum of all integers from 1 to n inclusive.

Examples:

No. Inputs Outputs
1 100 5050
2 16 136
3 1 1

Note:

The problem tests the ability to solve a quadratic equation and handle different cases of discriminant values.

Exercise 6: Star Pattern - Easy 😊 (Est. Time: 10-15 mins | Points: 10)

Problem: Write a program to print a pattern of * characters as shown in the output for a given value of n.

Input:

  • An integer representing the number of rows in the pattern.

Output:

  • A pattern of * characters as shown in the examples.

Examples:

No. Inputs Outputs
1 5 *
**
***
****
*****
2 3 *
**
***
3 7 *
**
***
****
*****
******
*******

Note:

The problem tests the ability to use loops and conditional statements to print a pattern of characters.

Exercise 7: Hash Pattern - Easy 😊 (Est. Time: 10-15 mins | Points: 10)

Problem: Write a program to print a pattern of # characters as shown in the output for a given value of n.

Input:

  • An integer representing the number of rows in the pattern.

Output:

  • A pattern of # characters as shown in the examples.

Examples:

No. Inputs Outputs
1 5 ##
#Β #
#Β Β #
#Β Β Β #
#Β Β Β Β #
2 3 ##
#Β #
#Β Β #
3 7 ##
#Β #
#Β Β #
#Β Β Β #
#Β Β Β Β #
#Β Β Β Β Β #
#Β Β Β Β Β Β #

Note:

The problem tests the ability to use loops and conditional statements to print a pattern of characters.

Exercise 8: Even Numbers - Easy 😊 (Est. Time: 10-15 mins | Points: 10)

Problem: Write a program to print all even numbers from 1 to n in a single row separated by a space. Use the continue statement to skip odd numbers.

Input:

  • An integer representing the upper limit of the range.

Output:

  • A sequence of even numbers from 1 to n inclusive, separated by a space.

Examples:

No. Inputs Outputs
1 10 2 4 6 8 10
2 7 2 4 6
3 20 2 4 6 8 10 12 14 16 18 20

Note:

The problem tests the ability to work with digits of a number.

Exercise 9: Multiples of a Number - Easy 😊 (Est. Time: 10-15 mins | Points: 10)

Problem: Write a program to print all integers from a to b inclusive that are multiples of c. The numbers a, b, and c are integers entered by the user.

Input:

  • Three integers representing the lower limit a, upper limit b, and the multiple c.

Output:

  • A sequence of integers from a to b inclusive that are multiples of c.

Examples:

No. Inputs Outputs
1 1
10
2
2 4 6 8 10
2 3
15
3
3 6 9 12 15
3 5
20
5
5 10 15 20

Note:

The problem tests the ability to work with digits of a number and compare their values.

Exercise 10: Pound to Kilogram Table - Easy 😊 (Est. Time: 10-15 mins | Points: 10)

Problem: Write a program to print a table of equivalence between mass in pounds and mass in kilograms for the values of n pounds (1 pound = 453 grams) in the form of a table.

Input:

  • An integer representing the number of pounds.

Output:

  • A table of equivalence between mass in pounds and mass in kilograms for the values of n pounds.

Examples:

No. Inputs Outputs
1 5 1 0.45
2 0.91
3 1.36
4 1.81
5 2.27
2 3 1 0.45
2 0.91
3 1.36
3 7 1 0.45
2 0.91
3 1.36
4 1.81
5 2.27
6 2.72
7 3.18

Note:

The problem tests the ability to use loops and conditional statements to print a table of values.

Exercise 11: Sum of a Series - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to calculate the sum of the expression 1/2 + 2/3 + 3/4 + …​ + n/(n + 1) for a given value of n.

Input:

  • An integer representing the upper limit of the range.

Output:

  • A floating-point number representing the sum of the expression 1/2 + 2/3 + 3/4 + …​ + n/(n + 1).

Examples:

No. Inputs Outputs
1 5 3.55
2 10 7.98
3 3 1.92

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a series.

Exercise 12: Sum of Three-Digit Numbers - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to calculate the sum of all three-digit numbers that are divisible by n, where n is an integer entered by the user.

Input:

  • An integer representing the number n.

Output:

  • An integer representing the sum of all three-digit numbers that are divisible by n.

Examples:

No. Inputs Outputs
1 125 3500
2 440 1320
3 600 600
4 1000 0

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a sequence of numbers.

Exercise 13: Password Validation - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to prompt the user for a password. If the user enters the wrong password, the program should display an error message and prompt the user to try again. If the user enters the correct password, the program should display a success message.

Input:

  • An integer representing the password.
  • A sequence of integers representing the password entered by the user.

Output:

  • A message indicating whether the password is correct or incorrect.

Examples:

No. Inputs Outputs
1 12345 111
Error
45
Error
12345
Done
2 123 111
Error
45
Error
12345
Error
123
Done
3 111 111
Done

Note:

The problem tests the ability to use loops and conditional statements to validate user input.

Exercise 14: Count of Zeros - Easy 😊 (Est. Time: 5 mins | Points: 10)

Problem: Write a program to determine how many of n numbers are equal to zero and output this count.

Input:

  • An integer n representing the number of integers to be entered.
  • n integers representing the numbers.

Output:

  • An integer representing the count of numbers that are equal to zero.

Examples:

No. Inputs Outputs
1 4
0
23
11
0
2
2 3
0
0
0
3
3 5
1
2
3
4
5
0

Note:

The problem tests the ability to use loops and conditional statements to count the number of occurrences of a specific value.

Exercise 16: Staircase Pattern - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to draw a staircase as shown in the output for a given value of n.

Input:

  • An integer representing the number of steps in the staircase.

Output:

  • A staircase as shown in the examples.

Examples:

No. Inputs Outputs Reference
1 4 Pattern 1
2 3 Pattern 2
3 7 Pattern 3

Output Patterns

Pattern 1

   #
  ##
 ###
####

Pattern 2

  #
 ##
###

Pattern 3

     #
    ##
   ###
  ####
 #####
######

Note:

The problem tests the ability to use loops and conditional statements to print a pattern of characters.

Exercise 17: Number Pattern - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to draw a pattern as shown in the output for a given value of n and m.

Input:

  • Two integers representing the number of rows n and the number of columns m.

Output:

  • A pattern as shown in the examples.

Examples:

No. Inputs Outputs
1 6
3
Pattern 1
2 3
3
Pattern 2
3 3
7
Pattern 3

Output Patterns

Pattern 1

0 	0 	0
1 	1 	1
2 	2 	2
3 	3 	3
4 	4 	4
5 	5 	5

Pattern 2

0 	0 	0
1 	1 	1
2 	2 	2

Pattern 3

0 	0 	0 	0 	0 	0 	0
1 	1 	1 	1 	1 	1 	1
2 	2 	2 	2 	2 	2 	2

Exercise 18: Number Pattern - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the total number of erors collected over n days.

Input:

  • An integer n representing the number of days.
  • n integers representing the number of errors collected each day.

Output:

  • An integer representing the total number of errors collected over n days.

Examples:

No. Inputs Outputs
1 6
45
101
67
43
21
0
277
2 3
0
0
0
0
3 5
1
2
3
4
5
15

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a sequence of numbers.

Exercise 19: Sum of Squares - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to print all two-digit numbers, the sum of the squares of the digits of which is divisible by n. The number n is an integer entered by the user.

Input:

  • An integer representing the number n.

Output:

  • A sequence of two-digit numbers, the sum of the squares of the digits of which is divisible by n.

Examples:

No. Inputs Outputs
1 5 12, 13, 17, 18, 21, 24, 26, 29, 31, 34, 36, 39, 42, 43, 47, 48, 50, 55, 62, 63, 67, 68, 71, 74, 76, 79, 81, 84, 86, 89, 92, 93, 97, 98
2 7 70, 77
3 10 13, 17, 24, 26, 29, 31, 34, 36, 39, 42, 43, 47, 48, 51, 53, 54, 57, 58, 62, 63, 67, 68, 71, 74, 76, 79, 82, 83, 87, 88, 91, 93, 94, 97, 98
4 100 68, 86
5 162 99

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 20: Odd Numbers - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to print all odd numbers from 1 to b, where b is an integer entered by the user. You cannot use the branching construct.

Input:

  • An integer representing the upper limit of the range.

Output:

  • A sequence of odd numbers from 1 to b inclusive.

Examples:

No. Inputs Outputs
1 15 1 3 5 7 9 11 13 15
2 8 1 3 5 7
3 5 1 3 5

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 21: Sum of Factorials - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to calculate the sum of the factorials of all integers from 1 to n inclusive.

Input:

  • An integer representing the upper limit of the range.

Output:

  • An integer representing the sum of the factorials of all integers from 1 to n inclusive.

Examples:

No. Inputs Outputs
1 3 9
2 4 33
3 5 153

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a series.

Exercise 22: Number Pattern - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to print all integers formed from the input number by discarding the last digit from each previous number.

Input:

  • An integer representing the input number.

Output:

  • A sequence of integers formed from the input number by discarding the last digit from each previous number.

Examples:

No. Inputs Outputs
1 138945 13894
1389
138
13
1
2 123456 12345
1234
123
12
1
3 987654 98765
9876
987
98
9

Exercise 23: Average of a Sequence - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to calculate the average of all integers in a sequence that ends with the number 0. The number 0 is not included in the sequence, but is used as a sign of its end.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • A floating-point number representing the average of all integers in the sequence.

Examples:

No. Inputs Outputs
1 3
4
5
0
4.0
2 1
2
3
4
5
0
3.0
3 10
20
30
40
50
0
30.0

Note:

The problem tests the ability to use loops and conditional statements to calculate the average of a sequence of numbers.

Exercise 24: Even Numbers - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the number of even elements in a sequence that ends with the number 0. The number 0 is not included in the sequence, but is used as a sign of its end.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • An integer representing the number of even elements in the sequence.

Examples:

No. Inputs Outputs
1 3
6
9
8
0
2
2 1
2
3
4
5
0
2
3 10
20
30
40
50
0
5

Note:

The problem tests the ability to use loops and conditional statements to count the number of occurrences of a specific value.

Exercise 25: Car Distance - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the number of days it takes for a car to cover a distance greater than t km, where the car covers d km on the first day and increases its distance by 10% each day.

Input:

  • Two integers representing the distance d and the target distance t.

Output:

  • A floating-point number representing the total distance covered and an integer representing the number of days it takes to cover a distance greater than t km.

Examples:

No. Inputs Outputs
1 10
100
114.36 km, 8 days
2 20
50
66.20 km, 3 days
3 5
25
30.53 km, 5 days
4 1
10
11.44 km, 8 days
5 50
100
155.13 km, 3 days

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a series.

Exercise 26: Sum of Digits - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the number of three-digit numbers, the sum of the digits of which is equal to a certain integer value n, which is entered by the user.

Input:

  • An integer representing the number n.

Output:

  • An integer representing the number of three-digit numbers, the sum of the digits of which is equal to n.

Examples:

No. Inputs Outputs
1 27 1
2 2 3
3 20 36

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 27: Sum of a Series - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to calculate the sum of the first n terms of the series Pi = 4/1 - 4/3 + 4/5 - 4/7 + ....

Input:

  • An integer representing the number of terms in the series.

Output:

  • A floating-point number representing the sum of the first n terms of the series.

Examples:

No. Inputs Outputs
1 10 3.0418396189294032
2 5 3.3396825396825403
3 15 3.017071817071818
4 120 3.1332594798865546
5 500 3.139592655589783

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of a series.

Exercise 28: Product of Two Numbers - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Given integers a and b. Find their product without using the multiplication operation.

Input:

  • Two integers a and b.

Output:

  • An integer representing the product of a and b.

Examples:

No. Inputs Outputs
1 7
8
56
2 5
6
30
3 3
4
12
4 10
10
100

Note:

The problem tests the ability to use loops and conditional statements to calculate the product of two numbers.

Exercise 29: Sum of Squares - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program that reads numbers (one per line) until the sum of the entered numbers equals 0, and immediately after that, outputs the sum of the squares of all the entered numbers. It is guaranteed that at some point the sum of the entered numbers will be 0, and reading should not continue after that.

Input:

  • A series of integers.

Output:

  • An integer representing the sum of the squares of all the entered numbers.

Examples:

No. Inputs Outputs
1 1
2
3
4
-4
-3
-2
-1
60
2 1
2
3
4
-10
130
3 1
2
3
4
-1
-2
-3
-4
60

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of the squares of a sequence of numbers.

Exercise 30: Amoeba Division - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: A single-celled amoeba divides into 2 cells every 3 hours. Determine how many cells there will be after t hours if there was initially one amoeba.

Input:

  • An integer representing the number of hours t.

Output:

  • An integer representing the number of cells.

Examples:

No. Inputs Outputs
1 6 4
2 9 8
3 24 256

Exercise 31: Lowest Temperature - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the lowest temperature over a period of time and whether the temperature has dropped below -18 degrees.

Input:

  • An integer representing the number of days.
  • n integers representing the temperatures for each day.

Output:

  • An integer representing the lowest temperature and a string representing whether the temperature has dropped below -15 degrees.

Examples:

No. Inputs Outputs
1 3
-20
2
-18
-20
Yes
2 5
-10
-15
-20
-25
-30
-30
Yes
3 7
-5
-10
-15
-20
-25
-30
-35
-35
Yes

Note:

The problem tests the ability to use loops and conditional statements to calculate the lowest temperature and determine whether it has dropped below a certain value.

Exercise 32: Car Speeds - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to determine the difference between the maximum and minimum speeds of the cars and the number of cars whose speed did not exceed 30 km/h. The program receives the number of recorded cars n (1 ≀ n ≀ 30) as input, followed by their speeds. The speed values cannot be less than 1 or greater than 300. The program should first output the difference between the maximum and minimum speeds of the cars, then the number of cars whose speed did not exceed 30 km/h.

Input:

  • An integer representing the number of recorded cars n (1 ≀ n ≀ 30).
  • n integers representing the speeds of the cars.

Output:

  • An integer representing the difference between the maximum and minimum speeds of the cars.
  • An integer representing the number of cars whose speed did not exceed 30 km/h.

Examples:

No. Inputs Outputs
1 3
15
25
140
125
2
2 5
10
20
30
40
50
40
3
3 7
5
10
15
20
25
30
35
30
6

Note:

The problem tests the ability to use loops and conditional statements to calculate the difference between the maximum and minimum speeds of the cars and the number of cars whose speed did not exceed a certain value.

Exercise 33: Two-Dimensional Table - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to output a two-dimensional square table of n x n numbers, where n is an integer entered by the user. The main diagonal of the table (from the top left value to the bottom right value) should contain 0, above the main diagonal should be 1, and below it should be -1. To display the table values nicely, use the tab character \t.

Input:

  • An integer representing the number n.

Output:

  • A two-dimensional square table of n x n numbers.

Examples:

No. Inputs Outputs
1 5 0 1 1 1 1
-1 0 1 1 1
-1 -1 0 1 1
-1 -1 -1 0 1
-1 -1 -1 -1 0
2 3 0 1 1
-1 0 1
-1 -1 0
3 7 0 1 1 1 1 1 1
-1 0 1 1 1 1 1
-1 -1 0 1 1 1 1
-1 -1 -1 0 1 1 1
-1 -1 -1 -1 0 1 1
-1 -1 -1 -1 -1 0 1
-1 -1 -1 -1 -1 -1 0

Note:

The problem tests the ability to use loops and conditional statements to print a two-dimensional square table of numbers.

Exercise 34: Number Pattern - Medium πŸ”₯ (Est. Time: 10-15 mins | Points: 20)

Problem: Write a program to print a pattern of number characters as shown in the output for a given value of n.

Input:

  • An integer representing the number of rows in the pattern.

Output:

  • A pattern of number characters as shown in the examples.

Examples:

No. Inputs Outputs
1 5 1
12
123
1234
12345
2 3 1
12
123
3 7 1
12
123
1234
12345
123456
1234567

Exercise 35: Odd Numbers - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to print all n-digit odd natural numbers in descending order.

Input:

  • An integer representing the number n.

Output:

  • A sequence of n-digit odd natural numbers in descending order.

Examples:

No. Inputs Outputs
1 1 9 7 5 3 1
2 2 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 36: Greatest Common Divisor - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the greatest common divisor (GCD) of two natural numbers a and b. Use the Euclidean algorithm.

Input:

  • Two natural numbers a and b.

Output:

  • An integer representing the greatest common divisor of the two numbers.

Examples:

No. Inputs Outputs
1 8
2
2
2 12
3
3
3 15
5
5

Note:

The problem tests the ability to use loops and conditional statements to calculate the greatest common divisor of two numbers.

Exercise 37: Division Without Division - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the results of the integer division of a by b and the remainder of the division of a by b, without using the standard integer division and remainder operations.

Input:

  • Two integers a and b (a > b).

Output:

  • Two integers representing the results of the integer division of a by b and the remainder of the division of a by b.

Examples:

No. Inputs Outputs
1 16
5
3 1
2 20
3
6 2
3 25
4
6 1

Note:

The problem tests the ability to use loops and conditional statements to calculate the results of the integer division and the remainder of the division of two numbers.

Exercise 38: Even Difference - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine whether the difference between the maximum and minimum digits of a natural number n is even.

Input:

  • A natural number n.

Output:

  • A boolean value representing whether the difference between the maximum and minimum digits of n is even.

Examples:

No. Inputs Outputs
1 2134389 True
2 1234 False
3 123456789 True

Note:

The problem tests the ability to use loops and conditional statements to determine whether a certain condition is met.

Exercise 39: Sum of Digits - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to calculate the sum of the digits of an integer n. The program should take into account that a negative integer may be entered.

Input:

  • An integer n.

Output:

  • An integer representing the sum of the digits of n.

Examples:

No. Inputs Outputs
1 -123 6
2 1 1
3 412098 24

Note:

The problem tests the ability to use loops and conditional statements to calculate the sum of the digits of an integer.

Exercise 40: Fibonacci Sequence - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to obtain the Fibonacci sequence from 0 to n, where n is an integer. The Fibonacci sequence is a series of numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, .... Each subsequent number is found by adding the two numbers before it.

Input:

  • An integer n.

Output:

  • A sequence of numbers representing the Fibonacci sequence from 0 to n.

Examples:

No. Inputs Outputs
1 50 1 1 2 3 5 8 13 21 34
2 100 1 1 2 3 5 8 13 21 34 55 89
3 200 1 1 2 3 5 8 13 21 34 55 89 144

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 41: Fibonacci Sequence Number - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to obtain the Fibonacci sequence number. The Fibonacci sequence is a series of numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, .... Each subsequent number is found by adding the two numbers before it.

Input:

  • An integer n.

Output:

  • An integer representing the n-th number in the Fibonacci sequence.

Examples:

No. Inputs Outputs
1 9 34
2 3 2
3 5 5

Note:

The problem tests the ability to use loops and conditional statements to print a sequence of numbers.

Exercise 42: Greater Than Next Element - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine how many elements in a sequence are greater than the next element. The sequence consists of integers and ends with the number 0. The program should take into account that the sequence contains at least two numbers.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • An integer representing the number of elements in the sequence that are greater than the next element.

Examples:

No. Inputs Outputs
1 2
9
1
4
3
0
2
2 3
1
2
3
4
0
0
3 5
1
2
3
4
5
0
1

Note:

The problem tests the ability to use loops and conditional statements to count the number of occurrences of a specific value.

Exercise 43: Second Largest Element - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the value of the second largest element in a sequence. The sequence consists of different natural numbers and ends with the number 0. The program should take into account that the sequence contains at least two numbers.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • An integer representing the value of the second largest element in the sequence.

Examples:

No. Inputs Outputs
1 1
4
3
2
0
3
2 3
1
2
3
4
0
3
3 5
1
2
3
4
5
0
4

Note:

The problem tests the ability to use loops and conditional statements to calculate the value of the second largest element in a sequence.

Exercise 44: Index of Largest Element - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the index of the largest element in a sequence. The sequence consists of natural numbers and ends with the number 0. The program should take into account that the sequence contains at least two numbers.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • An integer representing the index of the largest element in the sequence.

Examples:

No. Inputs Outputs
1 4
2
6
9
5
0
3
2 3
1
2
3
4
0
4
3 5
1
2
3
4
5
0
4

Note:

The problem tests the ability to use loops and conditional statements to calculate the index of the largest element in a sequence.

Exercise 45: Sign Changes - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine how many times the sign changes in a sequence. The sequence consists of non-zero integers and ends with the number 0. The program should take into account that the sequence contains at least two numbers.

Input:

  • A sequence of integers that ends with the number 0.

Output:

  • An integer representing the number of times the sign changes in the sequence.

Examples:

No. Inputs Outputs
1 -5
-3
10
6
-4
7
-1
0
4
2 3
1
2
3
4
0
0
3 5
1
2
3
4
5
0
0

Note:

The problem tests the ability to use loops and conditional statements to count the number of occurrences of a specific value.

Exercise 46: Position of a Digit - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the position of a given digit d in a natural number n, counting from the end of the number. If there is no such digit, the answer should be the number 0; if there are several such digits in the number, the position of the rightmost one should be determined.

Input:

  • A natural number n.
  • A digit d.

Output:

  • An integer representing the position of the rightmost occurrence of the digit d in the number n.

Examples:

No. Inputs Outputs
1 1233572
3
4
2 123456789
5
5
3 123456789
0
0

Note:

The problem tests the ability to use loops and conditional statements to calculate the position of a digit in a number.

Exercise 47: Palindromes - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the number of palindromes that do not exceed n, where n is an integer entered by the user.

Input:

  • An integer n (1 ≀ n ≀ 100000).

Output:

  • A sequence of numbers representing the palindromes that do not exceed n.

Examples:

No. Inputs Outputs
1 50 1 2 3 4 5 6 7 8 9 11 22 33 44
2 100 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99
3 200 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 111 121 131 141 151 161 171 181 191

Exercise 48: Number of Palindromes - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the number of palindromes that do not exceed n, where n is an integer entered by the user.

Input:

  • An integer n (1 ≀ n ≀ 100000).

Output:

  • A number representing the number of palindromes that do not exceed n.

Examples:

No. Inputs Outputs
1 50 13
2 100 18
3 200 28

Note:

The problem tests the ability to use loops and conditional statements to calculate the number of palindromes that do not exceed a certain value.

Exercise 49: Palindromes in an Interval - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Two four-digit numbers a and b are entered. Print all four-digit numbers in the interval from a to b that are palindromes (read the same from left to right and from right to left).

Input:

  • Two four-digit numbers a and b.

Output:

  • A sequence of four-digit numbers in the interval from a to b that are palindromes.

Examples:

No. Inputs Outputs
1 1400
2200
1441 1551 1661 1771 1881 1991 2002 2112
2 1000
2000
1001 1111 1221 1331 1441 1551 1661 1771 1881 1991
3 2000
3000
2002 2112 2222 2332 2442 2552 2662 2772 2882 2992

Note:

The problem tests the ability to use loops and conditional statements to calculate the number of palindromes that do not exceed a certain value.

Exercise 50: Number of Palindromes - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Write a program to determine the number of palindromes that do not exceed n, where n is an integer entered by the user.

Input:

  • An integer n (1 ≀ n ≀ 100000).

Output:

  • A number representing the number of palindromes that do not exceed n.

Examples:

No. Inputs Outputs
1 10 9
2 50 13
3 100 18
4 200 27

Note:

The problem tests the ability to use loops and conditional statements to calculate the number of palindromes that do not exceed a certain value.

Exercise 51: Three Identical Digits - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Two four-digit numbers a and b are entered. Print all four-digit numbers in the interval from a to b that contain only three identical digits.

Input:

  • Two four-digit numbers a and b.

Output:

  • A sequence of four-digit numbers in the interval from a to b that contain only three identical digits.

Examples:

No. Inputs Outputs
1 1400
1600
1411 1444 1511 1555
2 1000
2000
1111 1222 1333 1444 1555 1666 1777 1888 1999
3 2000
3000
2002 2111 2222 2333 2444 2555 2666 2777 2888 2999

Exercise 52: Odd Numbers - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Two numbers a and b are entered. Print all odd numbers from the interval from a to b (b ≀ a). Write a program without using a branching instruction.

Input:

  • Two integers a and b (a β‰₯ b).

Output:

  • A sequence of odd numbers from the interval from a to b.

Examples:

No. Inputs Outputs
1 10
1
9 7 5 3 1
2 20
1
19 17 15 13 11 9 7 5 3 1
3 30
1
29 27 25 23 21 19 17 15 13 11 9 7 5 3 1

Note:

The problem tests the ability to use loops to print a sequence of numbers.

Exercise 53: Even Numbers - Hard πŸ₯΅ (Est. Time: 15-20 mins | Points: 30)

Problem: Two numbers a and b are entered. Print all even numbers from the interval from a to b (a ≀ b). Write a program without using a branching instruction.

Input:

  • Two integers a and b (a ≀ b).

Output:

  • A sequence of even numbers from the interval from a to b.

Examples:

No. Inputs Outputs
1 1
20
2 4 6 8 10 12 14 16 18 20
2 1
30
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
3 1
40
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40

Note:

The problem tests the ability to use loops to print a sequence of numbers.

Problems in Order of Difficulty According to ChatGPT

The exercises provided range from understanding conditional statements to implementing complex branching logic. Here's a summary of the exercises ordered by difficulty, starting with the easiest and moving to more challenging problems.

Easy 😊

Total: 14

Medium πŸ”₯

Total: 19

Hard πŸ₯΅

Total: 18

Each exercise is designed to challenge different aspects of problem-solving, from simple arithmetic to complex logical reasoning. The estimated completion time for the exercises ranges from 5 minutes for the simplest tasks to 25 minutes for the most complex ones. This gives an average expected time of approximately 10-15 minutes per exercise, depending on the student's prior knowledge and experience.

Checking Your Score with Autograder πŸ“

GitHub Classroom's autograder provides immediate feedback on your exercises. Each exercise is worth points based on its complexity, with a total of 90 points available across all exercises.

When you commit and push your solution, GitHub Actions will run tests on your code. If all tests for an exercise pass, you will be awarded the full points for that exercise. If some tests fail, partial points may be awarded.

The workflow will run all tests, even if some fail. The total score will be shown in the workflow output as points scored/total points available. For example, if you see 10/90, it means you've successfully completed the first problem worth 10 points.

Please note that the workflow will show as failed if any test fails, even if you've successfully solved some problems. Look for the points tally in the output to see your score.

Remember, practice makes perfect! If you don't pass all tests the first time, review your code, make improvements, and try again. You can push new changes as many times as you need.

Running Your Code and Tests Locally πŸ–₯️

To run your code and tests locally, you can use the following commands:

  1. Run the code:
python exercises/exercise_1.py
  1. Run the tests:

To run the tests for an exercise, you'll use the pytest framework. First, make sure you have pytest installed:

pip install pytest

Then, you can run the tests for a specific exercise using the following command:

python -m unittest tests/test_exercise_1.py

And for more beautiful output, you can use:

pytest --color=yes -vv tests/test_exercise_1.py

or to run only failed test from a specific file:

pytest --color=yes --failed-first -x tests/test_exercise_1.py

Replace exercise_1 with the exercise you're working on (e.g., exercise_2, exercise_3, etc.) and test_exercise_1 with the corresponding test file.