You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by jdonwells March 11, 2022
As you may have seen here #365 I don't like contrived examples because it forces us into a position of showing code that isn't the best. I am often reminded of the old, old expression "you can write FORTRAN code in any language." Meaning that you can take an idiosyncrasy from one language to the next as baggage. Each language has a unique style, especially Python. It is tempting to write good Java examples as part of a Python class.
Starting with the Do Now we get caught up with stars. Using loops to create blocks of stars is a problem to me. We have already shown them how to create this code:
Which doesn't use any loops at all. Hence, it is a contrived example.
But on slide 7 of the pptx file there is an alternative that isn't contrived. There is a problem with the way it is written, but that can be fixed.
I am also going to replace the Lab which asks for the above code with no loops to be written. We should advocate eliminating most nested loops except when it is a natural thing to do. So only a one day lab is needed.
In this lab we will be drawing matrices to the console. A matrix will be represented by a list of lists. A list will contain rows. Each row is then represented by a list of individual items one per column.
These matrices could be used for some kind of game. Maybe they are used for some kind of calculations. Either way we must be able to show them in some useful and easy to understand format. That is your assignment.
You will write a single function, show_matrix(matrix) that will draw all 3 example matrices. You may create helper functions to be called by show_matrix(matrix) as needed. The solution may or may not be complex enough to warrant additional functions. You decide.
Copy and paste this starter code into your IDE. The functions make_random_row() and make_random_matrix() both use a new type of for loop to create a list. Write down in your notebook how you think they work. Notice that we are importing a single function from the random library with from import.
Notice that each item in the matrix is a single digit integer. Look carefully at how there is a single space on either side of the digit in the drawing. Do your best to replicate this output exactly.
Discussed in #367
Originally posted by jdonwells March 11, 2022
As you may have seen here #365 I don't like contrived examples because it forces us into a position of showing code that isn't the best. I am often reminded of the old, old expression "you can write FORTRAN code in any language." Meaning that you can take an idiosyncrasy from one language to the next as baggage. Each language has a unique style, especially Python. It is tempting to write good Java examples as part of a Python class.
Starting with the Do Now we get caught up with stars. Using loops to create blocks of stars is a problem to me. We have already shown them how to create this code:
Which doesn't use any loops at all. Hence, it is a contrived example.
But on slide 7 of the pptx file there is an alternative that isn't contrived. There is a problem with the way it is written, but that can be fixed.
I am also going to replace the Lab which asks for the above code with no loops to be written. We should advocate eliminating most nested loops except when it is a natural thing to do. So only a one day lab is needed.
Here is my slide show. https://docs.google.com/presentation/d/1mVnFa5v27qs6DK3X-IzGoEDMf8Q1FBezGKGd-wyGqL4/edit?usp=sharing
Here is my Lab:
Lab 4.03 - Loops
Instructions
In this lab we will be drawing matrices to the console. A matrix will be represented by a list of lists. A list will contain rows. Each row is then represented by a list of individual items one per column.
These matrices could be used for some kind of game. Maybe they are used for some kind of calculations. Either way we must be able to show them in some useful and easy to understand format. That is your assignment.
You will write a single function,
show_matrix(matrix)
that will draw all 3 example matrices. You may create helper functions to be called byshow_matrix(matrix)
as needed. The solution may or may not be complex enough to warrant additional functions. You decide.make_random_row()
andmake_random_matrix()
both use a new type of for loop to create a list. Write down in your notebook how you think they work. Notice that we are importing a single function from therandom
library withfrom import
.show_matrix()
function.An example solution to the above lab:
The text was updated successfully, but these errors were encountered: