Question

1) What is the output of the following program? Kindly trace the program by hand I will be asking similar questions in the fi

Kindly show the steps please. thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Task 1

  1. Code with explanation
i = 1                   #initializing i with 1

while i<=4:             #applying loop for iteration for condition i less or equal to 4

    print ("*"*i)       #printing pattern

    i = i+1             #incrementing i with 1 after each iteration

Output

Process finished with exit code 0

  1. code with explanation
i = 1                      #initializing i with 1

j = 2                      #initializing j with 2

while i>=1:                #applying loop for iteration for condition i greater or equal to 1

    a = " "*j+"*"*i+" "*j  #multiplying space and asterisk with variable i and j to print pattern 

    print (a)              #printing pattern

    i=i+2                  #incrementing i with 2

    j=j-1                  #decrementing j with 1

    if i>5:                #applying condition that if i greater then 5 then go out of loop using break

        break

        

        #upper block will provide first three lines of pattern

        #lower block will provide last two lines

i = 3                      

j = 1

while i >= 1:

    a = " "*j+"*"*i+" "*j

    print (a)

    i = i-2                 #decrementing i with 2

    j = j+1                 #incrementing j with 1

Output

Process finished with exit code 0

Explanation

in part a)

  • we have used simple while loop to print a specific pattern as shown in output snippet of part 1
  • starting with I initialize with 1
  • and on that I apply while loop upto I is less then or equal to 4
  • printing “*” into value of I times
  • incrementing i

in part b)

  • we have used two while loops to print a pattern with first increasing “*” and then decreasing as shown in output of part 2.
  • In first while loop we have printed three lines of asterisk with number of spaces depending upon size of j and number of asterisk depending upon size of i.
  • In second while loop we have printed 2 lines of asterisk decrementing accordingly as shown in output snippet of part 2.
Add a comment
Know the answer?
Add Answer to:
Kindly show the steps please. thank you 1) What is the output of the following program?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 6. Show the step-by-step trace through the following Fortran program segments and predict the output. a)...

    6. Show the step-by-step trace through the following Fortran program segments and predict the output. a) INTEGER I, J, K DO I = 2, 8, 2 DO J = I, 2 DO K = 1, J, 2 PRINT*, I, J, K ENDDO b) X = 1.0 DO WHILE (X .LE. 100.0) PRINT*, X X = (X-1)**2 + 2.0 END DO

  • need help debugging please need to know why isn't running and how to fix it Users\trinv\Downloads\Test...

    need help debugging please need to know why isn't running and how to fix it Users\trinv\Downloads\Test 3_Debugging Question(1).py - Notepad++ dit Search View Encoding Language Settings Tools Macro Run Plugins Window? ha LJ P2py x Test3 Plpy x B new i py Test_3_Debugging Question(1) py ") 6 str = input("Enter some text: ") 7 8 9 while (a < 0): 0 print(a) 1 a = a - 2 2 3 print(" 4 # # -5 26 for kin [1, 2,...

  • Please construct a program that runs as a counter: the program keeps asking users to enter...

    Please construct a program that runs as a counter: the program keeps asking users to enter a command. If the command is '+', it increases the counter by one; if the command is '-', it decreases the counter by one; and if the command is 'q', it stops asking input and prints out the total count. The following is an example of how the program would run: Total count is 2 The program is initialized as below count = 0...

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • 12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers...

    12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers are:') 3 for i in range (2,25): 4 isone (i) 5 def isone (number): isOne = True i = 2 while i < number and is one: if number % i == 0: 10 isOne = False 11 i += 1 Lou if isOne == True: 13 print("\t', i) 14 main() 12 13. What is the output of this program? Your answer: for i...

  • i want to make a matlab program that uses this information the information on the first...

    i want to make a matlab program that uses this information the information on the first column is w and the information on the second column is l how do i make matlab read the information on the second column? this is what i have so far ive already gotten matlab to read whats on the first columb bur i dont know how to make it read whats on the second column can you help me?thank you! EDIT Documents C...

  • Kindly assist with the following question. Please view image attached and include detailed steps. Thank you...

    Kindly assist with the following question. Please view image attached and include detailed steps. Thank you I want to make up 1 liter of 50 mM phosphate buffer, pH 6.8. I have 1 M phosphate buffer, pH 12 and 2 M HCI. How will I make up this buffer? 2.12 7.21 12.32 4 4

  • Please answer both questions thank you. Question 52 (1 point) What is the output of the...

    Please answer both questions thank you. Question 52 (1 point) What is the output of the code snippet given below? String s = "abcde"; int i = 1; while (i < 5) { System.out.print(s.substring(i, i + 1)); i++; Question 50 (1 point) How many times will the output line be printed in the following code snippet? Please enter your answer as an integer. for (int i = 0; i < 3; i++) { for (int j = 1; j <...

  • Using the following Java program, modify the code so that every time you run your program,...

    Using the following Java program, modify the code so that every time you run your program, it generates random numbers for your array, and then prints it (insertion sort) import java.awt.Graphics; import java.applet.Applet; public class SortingProg extends Applet { int a[] = { 55, 25, 66, 45, 8, 10, 12, 89, 68, 37 }; public void paint(Graphics g)     {       print(g,"Data items in original order",a,25,25);       sort();       print(g,"Data items in ascending order",a,25,55);     } public void sort() {...

  • Part 1: Python code; rewrite this code in C#, run the program and submit - include...

    Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT