DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on • Edited on

2

🤔 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)
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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs