Preview

Python Pattern Problem Hints

Good Essays
Open Document
Open Document
789 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Python Pattern Problem Hints
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+"*" Variables:
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

You May Also Find These Documents Helpful

  • Satisfactory Essays

    = z) return true; else return false; } Problem 5 a. Output: 720 b. Output: 0 c. Output: 71 d. Output: 362880 Problem 6 a. Output: “Take Programming I.” b. Output:…

    • 188 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    POW 9 IMP3

    • 1192 Words
    • 5 Pages

    Create 2 formulas, one that will calculate the last number in terms of the first number and a constant increase in rate as well as the total amount of numbers. The second formula will add ass of the resulting numbers from the first formula together after the last number is calculated.…

    • 1192 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    Nt1310 Unit 3 Quiz

    • 6337 Words
    • 26 Pages

    /*question number 1*/ Code: int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; What number will z in the sample code above contain? Choice 1 5 Choice 2 6 Choice 3…

    • 6337 Words
    • 26 Pages
    Good Essays
  • Good Essays

    ElizabethFlaimFP

    • 1289 Words
    • 7 Pages

    Problem Definition: Design a program that allows a user to input a list of family members, along with their age and the state where they live. The program will determine and print the average age of the user’s family. The program will also print the names of any family member that lives in Texas. The program design should also allow the user to enter at least 50 family members.…

    • 1289 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    21. Write a program that prompts the user to enter two unsigned numbers 0 to FFFFh and their sum in hex on the next line.…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Copy the Number of Attendees substitution values from the one-variable data table (in cells E3:E18), and then paste the values starting in cell E22.…

    • 659 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Nt1310 Unit 3 Assignment

    • 256 Words
    • 2 Pages

    Write a program to input a string and then display it in Upper Case and also print the frequency of any character from the string.…

    • 256 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Design Main program Declare Type as integer Declare 1 as string Declare 2 as string Declare 3 as string Declare 4 as string Declare 5 as string Declare Amount as real Declare MP_XRate as real Declare CD_XRate as real Declare EP_XRate as real Declare JY_XRate as real Declare FF_XRate as real Declare USD as real…

    • 762 Words
    • 12 Pages
    Good Essays
  • Satisfactory Essays

    6. In the “Cum Sum” column, calculate the cumulative sum (running total) of the subtotal count. You need to write a nested formula that combines IF, Sum, and ISNUMBER functions.…

    • 432 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Comp230 W2 Ilab

    • 1120 Words
    • 5 Pages

    StdOut. Write("Please Enter you age .....................") ageStr = WScript. StdIn.ReadLine() ' Calculate Age+10 and assign to ageStr10 ageStr10 = CStr( CInt(ageStr)+10 ) ' Display Name and Age Vales WScript.…

    • 1120 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    1. Problem definition: Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas.…

    • 467 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    c. Modify the program of Part b so that at the option of the user, it displays…

    • 300 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    It 210 Week 7

    • 286 Words
    • 2 Pages

    2. Display the contents of the file GRADES created in Problem 1. Each student’s record should appear on a separate line and include the total score (the sum of the three tests) for that student. For example, a line of output might be as follows:…

    • 286 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    3) Design an algorithm that does the following: Opens an output file with the external name number_list.dat, uses a loop to write the numbers 1 through 100 to the file and then closes the file.…

    • 544 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Mishra

    • 1486 Words
    • 6 Pages

    Once you have found the numeric results of your name and date of birth, you just need to add them again and you will get a single number by using the previous method:…

    • 1486 Words
    • 6 Pages
    Good Essays