Contenido del Curso
Learn Python from Scratch
Learn Python from Scratch
Indentation
Python is easy about rules, but indentation is one of the few rules Python requires to observe.
All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).
HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).
Example of a valid code:
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).
Tarea
Analyze the code snippet on the right and fix it
¡Gracias por tus comentarios!
Indentation
Python is easy about rules, but indentation is one of the few rules Python requires to observe.
All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).
HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).
Example of a valid code:
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).
Tarea
Analyze the code snippet on the right and fix it
¡Gracias por tus comentarios!
Indentation
Python is easy about rules, but indentation is one of the few rules Python requires to observe.
All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).
HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).
Example of a valid code:
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).
Tarea
Analyze the code snippet on the right and fix it
¡Gracias por tus comentarios!
Python is easy about rules, but indentation is one of the few rules Python requires to observe.
All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).
HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).
Example of a valid code:
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).
Tarea
Analyze the code snippet on the right and fix it