This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from introprogramming/feature/revise-control_flow
Update control_flow and rename to getting_started
- Loading branch information
Showing
17 changed files
with
131 additions
and
141 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 +1,4 @@ | ||
control_flow | ||
getting_started | ||
fibonacci | ||
robbers_language | ||
objects_in_a_bag | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/python | ||
|
||
# The boolean operators are not, and, or | ||
# Can you see how they work? | ||
print("not True: ", (not True)) | ||
print("True and True: ", (True and True)) | ||
print("True and False: ", (True and False)) | ||
print("True or False: ", (True or False)) | ||
print("False or False: ", (False and False)) | ||
print("") | ||
|
||
# Assigning a boolean value to a variable | ||
boolean_variable = True | ||
|
||
# You can reassign a variable | ||
boolean_variable = False | ||
boolean_variable = boolean_variable or True | ||
|
||
# Usage in if-else-statement | ||
if boolean_variable: | ||
print("boolean_variable is True") | ||
else: | ||
print("boolean_variable is False") |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/python | ||
|
||
|
||
def contains(input_list, e): | ||
""" determines whether e is contained in the list """ | ||
for elem in input_list: # elem is short for element (an item in the list) | ||
if elem == e: | ||
return True | ||
return False | ||
|
||
|
||
integer_list = [0, 1, 2, 3] | ||
|
||
print("") | ||
print("Does the list contain 3?:", contains(integer_list, 3)) | ||
print("Does the list contain 5?:", contains(integer_list, 5)) | ||
print("") | ||
|
||
list1 = [1, 2, 3, 4] | ||
list2 = [1, 2, 3, 4, 5, 6, 7] | ||
list3 = [1, 2, 3, 5] | ||
|
||
# Create a function which determines whether all elements in a list are | ||
# contained in another list. | ||
# Some tips: | ||
# - Use the contains function defined above. | ||
# - You want to check if each element in the sublist is contained in the list | ||
# - You can use boolean arithmetic, see the examples in boolean_arithmetic.py | ||
|
||
|
||
def sublist_contains(list, sublist): | ||
# Your code goes here | ||
return None | ||
|
||
|
||
# Some tests to make sure your function works. The value that your function | ||
# returns should match the expected value. | ||
print("") | ||
print("Expected True, Actually got:", sublist_contains(list2, list1)) | ||
print("Expected False, Actually got:", sublist_contains(list3, list1)) | ||
print("Expected True, Actually got:", sublist_contains(list1, list1)) | ||
print("") |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/python | ||
# import statement needed to access code and functions located in other files. | ||
import random | ||
|
||
|
||
def my_function(): | ||
""" A function with no parameters, only a return value. """ | ||
return 42 | ||
|
||
|
||
def boolean_function(bool_variable): | ||
""" A function with one parameter which is used to determine what to return """ | ||
if bool_variable: | ||
return "The boolean variable is True" | ||
else: | ||
return "The boolean variable is False" | ||
|
||
|
||
def print_my_coords(x=0, y=0): | ||
""" A function with 2 parameters and no return value. | ||
It also has default values for both parameters, these are used if you don't | ||
pass a value yourself """ | ||
print("Coordinates ({},{})".format(x, y)) | ||
|
||
|
||
print("my_function returns:", my_function()) | ||
print("boolean_function returns:", boolean_function(True)) | ||
print("boolean_function returns:", boolean_function(False)) | ||
|
||
print_my_coords(2, 5) | ||
print_my_coords(2) | ||
print_my_coords(y=5) | ||
print_my_coords() |
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 |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
|
||
if variable % 6 == 0: | ||
print("divisible by 6") | ||
|
||
if variable % 7 == 0: | ||
print("divisible by 7") | ||
|
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
13 changes: 7 additions & 6 deletions
13
exercises/control_flow/lists.py → exercises/getting_started/lists.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/python | ||
# A program which uses a for-loop to print "Hello, world!" 10 times | ||
|
||
for i in range(10): | ||
print("Hello, world!", i) |
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