Question

How can I following questions by using nested for loop in Python 3? Q1. ----1 ---2-...

How can I following questions by using nested for loop in Python 3?

Q1.

----1

---2-

--3--

-4---

5----

Q2

-----1-----​

----333----​

---55555---​

--7777777--​

-999999999-

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 
n = 5
for i in range(5):
    for j in range(5-i-1):
        print("-",end="")
    print(i+1,end="")
    for j in range(i):
        print("-", end="")
    print()
#############################
n = 5
n = 2*n-1
spaces = n//2
value = 1
for i in range(0,n,2):
    for t in range(spaces+1):
        print("-", end="")
    spaces -= 1
    for j in range(i+1):
        print(value,end="")
    for k in range(spaces+2):
        print("-",end="")
    print()
    value += 2
Add a comment
Know the answer?
Add Answer to:
How can I following questions by using nested for loop in Python 3? Q1. ----1 ---2-...
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
  • Create in Java: 1. Create a (nested) for loop that given a number prints a line...

    Create in Java: 1. Create a (nested) for loop that given a number prints a line with the number repeated as many times as the number itself, for example: 22 333 4444 000.- 2.Modify the nested for loop to specify in each line if the numbers are even or odd. For example: 1 (odd) 22 (even) 333 (odd) 4444 (even) Dona.... 3. Modify the nested for loop to only print odd numbers. For example: 333 55555 annan..

  • Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each...

    Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each element's value to an integer indicating the order in which it was processed by the nested loop (1, 2, 3, 4, 5, 6). 2) Display the elements in tabular format. Use the column indices as headings across the top, and the row indices to the left of each row.

  • Write a Python program (using a nested loop) to print out the following pattern (there is...

    Write a Python program (using a nested loop) to print out the following pattern (there is a space between the numbers next to each other). 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1

  • python Write a Python program to construct the following pattern, using a nested for loop. *...

    python Write a Python program to construct the following pattern, using a nested for loop. * * * * * * * * * * * * * * * * * * * * * * * * * * *

  • Convert the following nested for loop into a nested while loop: for(i = 1 ; i...

    Convert the following nested for loop into a nested while loop: for(i = 1 ; i <= rows; i++)                     {                         for (j = 1 ; j <= rows; j++)                             {                                 if (bombCells[i][j])                                     {                                         System.out.print(" * ");                                     }                                 else                                     {                                         System.out.print(" . ");                                     }                             }                         System.out.println();                     }

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • Can I have the code in Python and the output 2-3-B for GPA You previously calculated...

    Can I have the code in Python and the output 2-3-B for GPA You previously calculated a GPA using a loop; in this assignment you'll use a for loop A GPA, or Grade Point Average, is calculated by summing the grade points earned in a student's courses and then dividing by the total units The grade-points for an individual course are calculated by multiplying the units for that course by the appropriate factor depending upon the grade received A receives...

  • How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using...

    How can I fix that ? Can you please explain clearly ? main.cpp 2 3 using namespace 4. 5 int main() std; unsigned int x = 0b01101100; 8 9 10 12 13 14 15 16 17 18 19 20 21 unsigned int z = 0x12345678; unsigned int e 0x7; unsigned int w = 0x87654321; unsigned int =0x123; int 1; int 92; int Q3; int Q4; Q1=x&y; cout << bitset<8> (Q1) << endl; Q2=-(x| y); cout << bitset<8>(Q2) << endl; Q3=(z...

  • Using R, write an if-statement nested inside the for-loop that prints "three" instead of the output...

    Using R, write an if-statement nested inside the for-loop that prints "three" instead of the output "3", so that the output becomes: for (i in 1:6) { print(i * 2 - 1) } 1 “three” 5 7 9 11

  • Need in Python! Consider the following program and expected output. Rewrite it using a for loop...

    Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.   HINT: Stay with i as the main loop counter and let j control the break behavior.   i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...

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