-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ignacio Avas
committed
May 2, 2017
1 parent
b3f52c8
commit b76a900
Showing
5 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
Boilerplate | ||
----------- | ||
Toma de decisiones | ||
------------------ | ||
|
||
Insertar alguna introducción aquí. | ||
En programación, la toma de decisiones es la anticipación a las condiciones que pueden ocurrir durante la ejecución del programa, así como la espcecificación de las acciones tomadas de acuerdo a las condiciones. El programa determina que acción tomar y que sentencias ejecutar dependiendo del valor de las expresiones. El siguiente es un ejemplo de toma de decisiones encontrado en la mayoría de los lenguajes de programación: | ||
|
||
.. sourcecode:: python | ||
|
||
print('Some python code here') | ||
edad = 45 | ||
|
||
if edad > 18: | ||
print('Eres muy viejo') | ||
|
||
Python provee las sentencias "if", que consisten de una expressión booleana (True o False) seguida de uno o más sentencias, como la mostrada arriba. Las sentencias if pueden ser sucedidas por sentencias "else" que son ejecutadas si la condición del "if" no se cumple. | ||
|
||
.. sourcecode:: python | ||
|
||
x = 32 | ||
y = 2 | ||
|
||
if y == 0: | ||
print('El divisor no debe ser 0') | ||
else: | ||
print('El resultado es{0}'.format(x/y)) | ||
|
||
Las sentencias if pueden ser anidadas, permitiendo ejecutar código más complejo. | ||
|
||
.. sourcecode:: python | ||
|
||
age = 23 | ||
if age < 18: | ||
if age < 0: | ||
print('Age no es válido') | ||
print('Eres muy pequeño para manejar') | ||
else: | ||
print('Puedes manejar') | ||
|
||
|
||
|
||
Desafío | ||
------- | ||
|
||
Describir el desafío aquí. | ||
Usando el siguiente programa, modifica las variables para que el programa imprima las líneas "1", "2" y "3". | ||
|
||
.. sourcecode:: python | ||
|
||
# change this code | ||
first_number = 0 | ||
second_number = 0 | ||
|
||
# don't change this code | ||
if first_number > 15: | ||
print("1") | ||
if second_number > 15: | ||
print("2") | ||
|
||
if first_number < second_number: | ||
print("3") | ||
else: | ||
print("Error") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
Boilerplate | ||
----------- | ||
Decision making | ||
--------------- | ||
|
||
Insert some introduction here. | ||
Decision making is anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. Decision structures evaluate multiple expressions which produce True or False. The program determine which action to take and which statements to execute, depending of the value of the expressions. Following is an example of a typical decision making structure found in most of the programming languages: | ||
|
||
.. sourcecode:: python | ||
|
||
print('Some python code here') | ||
age = 45 | ||
|
||
if age > 18: | ||
print('You are too old') | ||
|
||
Python provides the "if" statements, consisting of a boolean expression followed by one or more statementsIf statements can be followed by an else "else" statements executed if the top "if" condition doesn't held. | ||
|
||
.. sourcecode:: python | ||
|
||
x = 32 | ||
y = 2 | ||
|
||
if y == 0: | ||
print('divisor y should not be zero') | ||
else: | ||
print('Result is {0}'.format(x/y)) | ||
|
||
If statements can be nested allowing more complex logic to be executed: | ||
|
||
.. sourcecode:: python | ||
|
||
age = 23 | ||
if age < 18: | ||
if age < 0: | ||
print('Age is invalid') | ||
print('You are too young to drive') | ||
else: | ||
print('You are allowed to drive') | ||
|
||
|
||
|
||
Challenge | ||
--------- | ||
|
||
Describe the challenge here | ||
Using the following program, modify the variables so the program prints the lines "1", "2", and "3" | ||
|
||
.. sourcecode:: python | ||
|
||
# change this code | ||
first_number = 0 | ||
second_number = 0 | ||
|
||
# don't change this code | ||
if first_number > 15: | ||
print("1") | ||
if second_number > 15: | ||
print("2") | ||
|
||
if first_number < second_number: | ||
print("3") | ||
else: | ||
print("Error") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
.. sourcecode:: python | ||
|
||
print('Some solution here') | ||
# change this code | ||
first_number = 20 | ||
second_number = 22 | ||
|
||
# don't change this code | ||
if first_number > 15: | ||
print("1") | ||
if second_number > 15: | ||
print("2") | ||
|
||
if first_number < second_number: | ||
print("3") | ||
else: | ||
print("Error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters