DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on Edited on

ðŸĪ” Python Quiz: Are you formatting your snakes?

Follow me to learn 🐍 Python in 5-minute a day fun quizzes!
Follow me and don't miss the next quiz!

Find previous quiz here.

Are you ready to put your Python coding style to test? Let's dive into a quick but intriguing quiz based on PEP 8, the style guide for Python code.

Code formatting might seem trivial, but it's crucial for maintaining readable and clean code.

Quiz 2 out of 64

Which one of these code samples is done right according to PEP 8? Answer with 0 for the first sample or 1 for the second sample.

Sample 1

def calculate_area(length, width):
    return length * width

area = calculate_area(10, 20)
print(area)
ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

Sample 2

def calculate_area(length,width):
return length*width
area=calculate_area(10,20)
print (area)
ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

Post your answer in the comments – is it 0 for the first sample or 1 for the second? And don't forget to explain why you chose that answer. Let's see how many of you are true PEP-8 pros! 🐍ðŸ’ŧ

or Go to Quiz 3/64

Top comments (3)

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
vladignatyev profile image
Vladimir Ignatev •

The first code sample adheres to PEP-8 guidelines, which include using spaces around operators and after commas, and proper indentation for readability.

The second code sample violates several PEP-8 recommendations, such as lacking spaces around operators and after commas, and improper indentation. This can lead to less readable and maintainable code.

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
aj-esh profile image
Ajeesh Sunil •

Sample 1
200

Sample 2
ERROR

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: vladignatyev/python quiz pep formatting quiz - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
aj-esh profile image
Ajeesh Sunil •

Sample 1
200

Sample 2
ERROR