100 Python Practice Problems for Beginners
If you have just learned Python syntax, work through these 100 problems in order. Each topic starts with the easiest ones, and you can run and check every answer on this site with nothing to install.
1. Input and output #1–9
input() gives you one line as a string.
To use it as a number, write int(input()).
When one line has several numbers, read them with map(int, input().split()).
Shape your output with sep and end in print, and with f-strings.
Syntax refresher: Python input(): Read User Input · Python print(): Output with sep and end · Python split(): Split a String into a List · Python f-string: Format Numbers and Text
2. Variables and types #10–21
Python integers have no size limit, so you do not need to worry about overflow as in other languages.
But mixing a string and a number, as in "3" + 4, raises TypeError, so always keep track of whether the value you read is a string or a number.
Swapping two values takes one line: a, b = b, a.
- Marbles passed in turn8P0251
- The shorter one stands in front8P0344
- Four lines of true and false8P0217
- Ticket number from a seat code8P0226
- Sale price, or list price if there is none8P0281
- Swap the cards8P0046
- Big sum8P0015
- Truncate, floor, round8P0044
- A siren that keeps sounding until switched off8P0289
- Letter chain8P0045
- Ride capacity8P0086
- Three hops to the power box contact8P0286
3. Arithmetic #22–33
/ always gives a float, and // gives the quotient rounded down.-7 // 2 is -4 and -7 % 2 is 1 (the remainder takes the sign of the divisor).round() goes to the even side when the value is exactly halfway, so when the output asks for a set number of decimal places, f"{x:.2f}" is the safer choice.
- Distance per liter8P0216
- Sum of digits8P0006
- How many combinations a luggage lock has8P0423
- Grid distance8P0017
- Grading addition homework8P0222
- Seconds to H:MM:SS8P0013
- Free-throw success rate sheet8P0314
- Weekday after k days8P0016
- Round half to even8P0048
- This year's savings goal rate8P0407
- Powers that fit8P0050
- Closest to the target8P0218
4. Conditionals #34–44
Split into branches with if, elif and else.
You can chain a range, as in 0 <= x < 10, and ask whether a value is one of several with x in (1, 3, 5).
Indentation is the block, so being off by a single space changes the meaning.
- A photo fitted to a square frame8P0254
- Letter grades8P0011
- Leap year8P0019
- Locker extra fee8P0372
- Three-day temperature trend8P0227
- Member discount and delivery fee8P0191
- Kite-flying notice board8P0315
- Middle of three8P0020
- Four-operation calculator8P0021
- Password rule checker8P0098
- Due dates that skip closed days8P0431
5. Loops #45–56
range(a, b) does not include b.
To count down, use range(n, 0, -1).
When you also need the position, use enumerate.
When you do not know how many times to repeat, use while together with break.
Syntax refresher: Python for Loop · Python range(): Start, Stop and Step · Python while Loop · Python break vs continue
- Clap game8P0002
- Star triangle8P0007
- One row of the times table8P0022
- One more throw for yut or mo8P0255
- First multiple8P0023
- Street lamps, with one at the very end8P0371
- A reading marathon that grows every day8P0282
- Fibonacci number8P0010
- Counting temperature records8P0219
- Count the digits8P0052
- Loading a delivery truck in order8P0223
- Count down by steps8P0024
6. Strings #57–68
Strings cannot be changed (they are immutable), so s[0] = "a" does not work.
You have to build a new string.
Reverse with s[::-1], split with split, and join back together with "separator".join(items).
Syntax refresher: Python Slicing: [start:stop:step] Explained · Python split(): Split a String into a List · Python join(): Join a List into a String
- Count the vowels8P0009
- First and last position of a character8P0053
- Letters picked along the diagonal8P0283
- Count the words8P0012
- Palindrome check8P0004
- Reverse it, keep the sign8P0252
- Swap the case8P0025
- A price tag with dots and commas swapped8P0412
- Characters left in a message with Korean text8P0341
- Letter numbers in a note8P0192
- Cut from the a-th to the b-th character8P0054
- Reverse the word order8P0028
7. Lists #69–79
b = a does not copy.
It puts one more name on the same list.
To work on a separate one, copy it with a[:] or a.copy().a.sort() changes that list and returns None, while sorted(a) returns a new list.
Syntax refresher: Python List append(), extend() and insert() · Python sort() vs sorted(): Sort a List · Python Slicing: [start:stop:step] Explained
- Largest number and its position8P0005
- Numbers of the students who retake8P0374
- Showing one page of a board8P0284
- Sort the numbers8P0036
- Sorting sign letters8P0253
- Is it on the list?8P0059
- Swapping places in pairs8P0312
- Travel time on a one-way bus route8P0224
- Remove every match8P0058
- Rotate a list right8P0032
- Row and column sums8P0033
8. Sum, average, maximum #80–84
sum, max, min and len are built in.
It helps to work them out with your own loop first and then shorten the code with the built-in functions.
When a problem asks for the average as an integer, use //.
When it asks for a decimal, use /.
9. Functions #85–92
Make one with def and give a value back with return.
Without return you get None back, so watch out for the mistake of only calling print on the result and not returning it.
- A thermometer that cannot leave its scale8P0402
- Balls that landed in the sandbox8P0285
- Prime check8P0008
- A running course made of three flags8P0435
- A box-count function with defaults8P0257
- Tidy locker numbers8P0196
- Hall chairs numbered in a zigzag8P0428
- Pick the top word with a key function passed in8P0318
10. Dictionaries (dict) #93–100
Use one to look up a value by name.
Reading a missing key with d[k] raises KeyError, so in counting problems use get, as in d[k] = d.get(k, 0) + 1.
Syntax refresher: Python Dictionary (dict): Keys and Values
Good to know
- Your output has to match down to the last character. Make the spaces, line breaks and decimal places exactly the same as in the example.
- When you get an error, read the error name on the last line first. Common errors are sorted by cause in Error Messages.
- If you are stuck, go to "Lessons for this problem" on the problem page, review just that piece of syntax, and come back.
See also
- Python List Practice Problems — 58 problems
- 100 Coding Challenges for Beginners — 100 problems
- 100 C Programming Practice Problems for Beginners — 100 problems
- Learn Python — lessons with explanations and examples
- Python reference
- Python error messages
- Other problem sets