Python Pattern Problem Hints

Topics: Multiplication, Number, String Pages: 3 (789 words) Published: March 16, 2011
Pattern Problem Hints
1. Program 
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 
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 
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 
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...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Python Essay
  • STRESS pattern Essay
  • Python Essay
  • Social Problems Essay
  • Essay about Problem
  • problem Essay
  • Problems Essay
  • Fundamentals of Pattern Grading and CA Essay

Become a StudyMode Member

Sign Up - It's Free