Pattern Problem Hints
1. Program pat1.py.
Variables: This program gets a number from the user. We need a variable to hold the number. We need to print the numbers from 1 up to the user's number. We need a second variable for this. Program Plan: Get the user’s number. Convert it to a number. Initialize the print Number. What should the first number printed be? While the print Number is less than or equal to the user Number: print the user Number and increase it by 1.
2. Program pat2.py.
Program Plan: Get the users number. Convert it to a number. At this point there are two ways to proceed. We can do a multiplication to get the correct number of astersisks Or start with the empty string
s = ""
Then have a counting loop that adds one asterisk to s during each repetition: s = s+"*"
3. Rectangle. Program pat3.py.
Variables: There are two numbers to get from the user. So we need at least two variables. Program Plan: Once we have gotten the numbers from the user and converted them to numbers. We can make a row by multiplying a string containing a single asterisk by the number of asterisks in a row. If we add the string "\n" to the end of this (Remember the new line stops the current line when printed) we have a complete line. Now multiply all this (put it in parentheses and mul the parentheses) by the number of rows. Print this expression.
4. Triangle. Program pat4.py.
Variables: We need a variable to store the number of rows. as we will discover we will need another variable as a counter for a counting below. Program Plan: First step is to get the number of rows and convert it to a number. Now let's look at the triangle a row at a time we need one asterisk in the first row. Then two in the second and three in the third and so on. Think print i * "*"
If i has a 1 it we print a row with 1 asterisk. If i has a 2 in it the statement prints a row with two asterisks. So put the...
Please join StudyMode to read the full document