Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Doing Mistakes

hey guys so am learning Python from codeacadymy and other few resourse , but while practing am keep repating spaces mistake , i do i know where to put "spaces" and where i should add ":"

ex

like in this code

def fizz_count(x):
 count = 0
 for item in x:
   if item == "fizz":          #i forgot to add semicolon here
     count = count + 1
   return count
According to PEP8, which is a document that explains how to properly style your python code, you're supposed to add 4 spaces before lines that should be nested. In all of your lines after 'def fizz_count(x):' you only have one space. You should use 4 spaces instead. It's acceptable, though not reccommended, to used a tab for in place of the 4 spaces (but please don't do this, it's a bad habit!).

This is how your code should be properly formatted:
Code
def fizz_count(x):
   count = 0
   for item in x:
        if item == "fizz":          #i forgot to add semicolon here
            count = count + 1
   return count

[PS] If x is a list ( type(x) == 'list' ), then you can simplify your code to:
x.count('fizz')
(Aug 6, 2018 06:46 PM)lowfatcheeze Wrote:  According to PEP8, which is a document that explains how to properly style your python code, you're supposed to add 4 spaces before lines that should be nested. In all of your lines after 'def fizz_count(x):' you only have one space. You should use 4 spaces instead. It's acceptable, though not reccommended, to used a tab for in place of the 4 spaces (but please don't do this, it's a bad habit!).

This is how your code should be properly formatted:

def fizz_count(x):
   count = 0
   for item in x:
       if item == "fizz":          #i forgot to add semicolon here
           count = count + 1
   return count


[PS] If x is a list ( type(x) == 'list' ), then you can simplify your code to:
x.count('fizz')

You telling me to add 4 spaces but you yourself removed every single space
(Aug 6, 2018 06:46 PM)lowfatcheeze Wrote:  According to PEP8, which is a document that explains how to properly style your python code, you're supposed to add 4 spaces before lines that should be nested. In all of your lines after 'def fizz_count(x):' you only have one space. You should use 4 spaces instead. It's acceptable, though not reccommended, to used a tab for in place of the 4 spaces (but please don't do this, it's a bad habit!).

This is how your code should be properly formatted:

def fizz_count(x):
   count = 0
   for item in x:
       if item == "fizz":          #i forgot to add semicolon here
           count = count + 1
   return count


[PS] If x is a list ( type(x) == 'list' ), then you can simplify your code to:
x.count('fizz')

(Aug 6, 2018 07:05 PM)CyberError Wrote:  You telling me to add 4 spaces but you yourself removed every single space

You're supposed to. I'm not sure why no spaces are showing in my original post, yet your quote of my post has the spaces.
(Aug 6, 2018 07:23 PM)lowfatcheeze Wrote:  You're supposed to. I'm not sure why no spaces are showing in my original post, yet your quote of my post has the spaces.

Oh yeah , thanks for the reply
Is their any guide or topic so I can read about spaces ? With suitable examples
(Aug 6, 2018 07:41 PM)CyberError Wrote:  Oh yeah , thanks for the reply
Is their any guide or topic so I can read about spaces ? With suitable examples

I don't know of a good guide for them, but the concept is called "nesting." You might want to google something like "python nesting" and see if there's anything helpful for you. Let me know if you can't get it after some time researching.
(Aug 6, 2018 09:03 PM)lowfatcheeze Wrote:  I don't know of a good guide for them, but the concept is called "nesting." You might want to google something like "python nesting" and see if there's anything helpful for you. Let me know if you can't get it after some time researching.

when i searched for python nesting i found "python looping: tut


anyways thanks i found something , when i searched spaces in python

http://www.annedawson.net/Python_Spaces_...ation.html


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by HackersFeb 3, 2025 08:24 AM 0 168 Feb 3, 2025 08:24 AM
Last Post: Hackers
[C] by BulgarianFeb 28, 2016 02:00 PM 5 208 Feb 28, 2016 02:00 PM
Last Post: Bulgarian
[C] by Warren BuffettMar 19, 2015 10:34 PM 5 231 Mar 19, 2015 10:34 PM
Last Post: RTLZER0