Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
py-quickstart/docs/Iteration/for-loops/example-5.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (24 sloc)
780 Bytes
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
# example-5.py first example | |
# Nested Loops, some examples of nested for loops | |
print("First Example") | |
adjective = ["red", "big", "tasty"] | |
fruits = ["apple", "banana", "cherry"] | |
for x in adjective: | |
for y in fruits: | |
print(x, y) | |
# example-5.py second example | |
number = ["3", "2", "1", "100"] | |
adjective = ["red", "big", "tasty"] | |
fruits = ["apple", "banana", "cherry"] | |
count = 0 | |
for x in number: | |
for y in adjective: | |
for z in fruits: | |
count += 1 | |
print(x, y, z) | |
total = len(number) * len(adjective) * len(fruits) # Multiplied as explained in the README.md | |
if count == total: | |
print("We just proved how to calculate the number of times a loop runs!!") | |
print(count) | |
else: | |
print("Epic fail dood!!") |