10 easy Python and SQL tasks that turned out to be difficult:

Prologue

Now IT is a very demanded sphere: the demand for specialists is huge, new junes “enter” the industry every day. This means that the competition for a place in the sun among novice programmers / analysts is heating up every day.

What to do in such a situation? That’s right – use every opportunity to pump up a little. Since there is a lot of information and a confusion arises in the head, a good way is to solve simple problems and sort out questions. It’s convenient – while you’re on the subway, you can solve a couple of problems and put your knowledge in order a little.

We have been posting on our social networks for more than a year (In contact with, Telegram, Instagram) tasks of varying complexity in programming and related topics: Python, SQL, Data Science, Git, Analytics and other topics… We even have a special section for this – GROK IT. You can find it out by our signature duck 🙂

So, during all this time we have repeatedly come across such thoughts when planning the next task: “Well, no, it’s too easy, people will simply unsubscribe from us for such trivial tasks.”… However, everything turned out differently.

We have collected for you 10 interesting mini-tasks in Python and SQL, which seem very simple, but the overwhelming majority of those surveyed gave wrong answers… Here is such a statistic ¯ _ (ツ) _ / ¯

A few words about us 🙂 We are the IT Resume team and we are creating a cool platform for preparing for technical interviews and developing our skills. Soon there will be the first release, so we are waiting for you;)

In the meantime, subscribe to our social networks, where we post interesting and useful content on programming, Data Science and analytics.

For every taste: In contact withTelegramInstagram

So let’s finally get to the tasks. Let’s go 🙂

Task 1. The extend method in Python

Formulation:

# Дан список l. Что выведет код?   

l = [1, 2, 3]
l.extend('abc')
print(l)

Answer options:

[1, 2, 3, 'abc']
[1, 2, 3]
Error
[1, 2, 3, 'a', 'b', 'c']

Correct voices: 36%, wrong – 64%

We were very surprised – seemingly extend – is the standard list method in Python. But no – for the overwhelming majority, he caused difficulty.

Correct answer:

Detailed analysis of the problem here

By the way, we publish even more tasks in our private chats. In contact with and Telegram… We will be glad to see you there and solve problems together! 🙂

Problem 2. A tuple with one element

Formulation:

# Что выведет код? 

for i in (3):
	print(i)

Answer options:

1, 2, 3
3
(3)
Error

Correct voices: 33%, wrong – 67%

Overall, we assumed that many would fall into this trap. But in the end, even more people fell for her than we thought – hundreds of people!

Correct answer:

Detailed analysis of the problem here

Problem 3. Curly braces in f-strings

Formulation:

# Что выведет код? 

print('Curly brackets: {}')

Answer options:

Curly brackets: {}
Curly brackets: 
Ошибку
Ни один из вариантов

Correct answers – 22%, wrong – 78%

Here, too, we thought, to be honest, that the answer is straightforward: f-strings are, after all, very basic Python. But we were wrong again.

Correct answer

Detailed analysis of the problem here

Task 4. DELETE + CTE in SQL

Formulation:

-- Дана таблица Demo. 
-- Как изменится таблица после выполнения запроса в PostgreSQL? 

WITH temp_tab AS (
	DELETE FROM Demo
)
INSERT INTO Demo
SELECT * FROM temp_tab 

Answer options:

Никак, т.к. INSERT вставит удаленные строки
Никак, т.к. запрос не выполнится
Станет пустой, т.к. DELETE ничего не возвращает и вставлять нечего
Никак, т.е. INSERT нельзя использовать с CTE

Correct answers: 28%, wrong – 72%

Unlike the previous tasks, here we assumed that some kind of ambush awaited people 🙂 Still, not everyone knows about CTE, RETURNING, and so on. Actually, that’s what happened. But on the other hand, many are now familiar with the new SQL construct.

Correct answer

No way, tk. the request will fail.

Detailed analysis of the problem here

By the way, here here we explain in detail how and why to use Common Table Expressions. Including about DELETE.

Problem 5. Python’s Tricky AND Operator

Formulation:

# Что выведет код? 

print(50 and 100)

Answer options:

50 100
50
100
Ни один из этих вариантов

Correct answers – 13%, wrong – 87%

The statistics speak for themselves. This is the case when you suddenly forget which hand to hold the fork in. Everything seems to be obvious – 2 numbers and the AND operator. And you don’t understand what will happen in the end. And almost nobody understands.

Correct answer

Detailed analysis of the problem here

Problem 6. Shrug face and escape sequences in Python

Formulation:

# Что выведет код? 

print('¯\_(ツ)_//¯')

Answer options:

'¯\_(ツ)_//¯'
'¯_(ツ)_//¯'
'¯\_(ツ)_/¯'
Ничего из перечисленного

Correct answers – 28%, wrong – 72%

Of course, we posted this task for fun, because everyone loves kaomoji 🙂 But in fact, we encountered such a situation when developing the platform – we wanted to pass a shrug face as a string and came across interesting escaping effects. So it’s quite a business task!

Correct answer

Detailed analysis of the problem here

Task 7. Dropping the SQL Table

Formulation:

What query will work without errors in PostgreSQL?

Answer options:

DELETE * FROM Demo;
DELETE FROM Demo;
TRUNCATE TABLE Demo;
TRUNCATE * FROM Demo;

Correct answers – 28%, wrong – 72%

This is another question in the series “Which hand do I hold the fork with?” Due to the fact that some operations are done automatically, you do not get stuck – but what is the right way, and such tasks can lead to a stupor. And what is really there – many in general do not know how to delete a table and what is the difference between DELETE and TRUNCATE.

Correct answer

DELETE FROM Demo. Not obvious, but check 🙂

Detailed analysis of the problem here

Task 8. Adding elements to the set

Formulation:

# Что выведет код? 

set1 = {1, 2, 3}
set2 = set1.add(4)

print(set2)

Answer options:

{1, 2, 3, 4}
True
None
Error

Correct answers: 16%, wrong – 84%

Standard methods for lists, sets, dictionaries, etc. in Python, they are, perhaps, not completely obvious. In the sense that some methods return values, some do not return anything. Every time you get confused about this, the add method is a prime example.

Correct answer

Detailed analysis of the problem here

By the way, recently we did A selection of 5 must-know set methods… Don’t forget to check yourself;)

Problem 9. Combining Comparison Conditions in Python

Formulation:

# Что выведет код? 

print(11 > 0 and True)

Answer options:

True
False
Error

Correct answers – ten%, wrong – 90%

Well, this task is not at all obvious. Python, although it preaches transparency, but this construction is not directly transparent at all, as it seems to us (:

Correct answer

Detailed analysis of the problem here

Task 10. Import of PEP8 Libraries

Formulation:

# Сколько правил PEP8 нарушено при таком импорте библиотек?

import face_recognition
import sys, os
import mymodule # пользовательский скрипт
from subprocess import Popen, PIPE

Answer options:

1
2
3
4

Correct answers – 25%, wrong – 75%

It’s one thing to write code, and another thing to write the code correctly. And not everyone does it, although in fact it is very important: after a year it is simply impossible to read dirty code – sometimes it is easier to just rewrite it. PEP8 in Python is perhaps the basic guide to this. But it turns out that almost no one knows him 🙂

Correct answer

Detailed analysis of the problem here

By the way, on this occasion, we did a whole spring Python Code Style Guide – we highly recommend watching 🙂

Almost an epilogue

Agree, all these 10 tasks seem very easy at first glance. But when you start to understand a little deeper, you realize that often your knowledge is not that strong 🙂 Even a seasoned pro can fail on some tasks – not because something is wrong with him, but because some things have already been brought to automatism that you don’t even get hung up on trifles.

By the way, in chats In contact with and Telegram we try to answer in detail all the solutions that you send, so we look forward to hearing from you! 🙂 And we still have a lot of programming, Data Science and analytics tasks ahead.

Epilogue

As a conclusion, here’s another Python puzzle. Let’s see if you can solve it;)

Formulation:

Дан Pandas-датафрейм df, заполненный числами: 

+----------+----------+----------+
|   col1   |   col2   |   col3   |
+----------+----------+----------+

Write code to find the maximum absolute value of the correlation of each column with other columns. The result should have been presented as a list.

Send your solutions to the chats – there you will find out the correct answer! Will wait 😉


PS If for someone these tasks seemed too easy or “unviable”, then we do not pretend to do this 🙂 Our tasks help people to pump their knowledge of the intricacies of the language in a playful way and pay attention to the little things that fall out in everyday harsh life out of sight. We do not teach how to roll out whole combines into production, but le bon Dieu est dans le détail, as they say 😉

Similar Posts

Leave a Reply

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