DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on • Updated on

๐Ÿค” Python Quiz 2/64: 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)
Enter fullscreen mode Exit fullscreen mode

Sample 2

def calculate_area(length,width):
return length*width
area=calculate_area(10,20)
print (area)
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
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.

Collapse
 
aj-esh profile image
Ajeesh Sunil

Sample 1
200

Sample 2
ERROR

Collapse
 
aj-esh profile image
Ajeesh Sunil

Sample 1
200

Sample 2
ERROR