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

    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

    unit 3

    • 313 Words
    • 2 Pages

    Design a program that calculates the total amount of meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. Display each of these amounts and the total.…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    PT1420 Unit 8 Lab 8

    • 365 Words
    • 2 Pages

    Incrementing by Values Other than 1, page 190): Display numbers starting at 0 through 10 by increments of 2. 0,2,4,6,8,10…

    • 365 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    a1 script win213

    • 380 Words
    • 2 Pages

    If the user does not enter a numeric value the program should prompt for a numeric value…

    • 380 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    PT1420 Chapter 3 Review

    • 1062 Words
    • 8 Pages

    4. Assume the variables result, w, x, y, and z are all integers, and that w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements?…

    • 1062 Words
    • 8 Pages
    Satisfactory Essays
  • Satisfactory Essays

    It210 Appendix F

    • 372 Words
    • 3 Pages

    1. The program will present a series of user screens that prompts the user for specified input.…

    • 372 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    12. The STO→ button stores numbers to variables. To evaluate the expression23 4 a c b + −, press 9 STO→ ALPHA MATH ENTER to store the number 9 to A. Repeat this same process if B = 2 and C = 1, then evaluate the expression by…

    • 641 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    unit 8 homework

    • 793 Words
    • 5 Pages

    3. Design a For loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000…

    • 793 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    2) Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Lab 3 Student

    • 1264 Words
    • 7 Pages

    Step 1: This program is most easily solved using just a few variables. Identify potential problems with the following variables declared in the pseudocode. Assume that the college has the ability to offer half credits. (Reference: Variable Names, page 39-40).…

    • 1264 Words
    • 7 Pages
    Satisfactory 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

    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

    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
  • Satisfactory Essays

    * If your First Letter column is a number, you want to add the count…

    • 432 Words
    • 2 Pages
    Satisfactory Essays