Showing posts with label Nested Loop. Show all posts
Showing posts with label Nested Loop. Show all posts

Looping Statement Test 5

  

Looping Statement Test 5

Q1. Write program to print the following pattern.

a.     1

1 2

1 2 3

1 2 3 4

 

b.     * * * *

* * *

* *

*

Q2. Accept 10 numbers from the user and display

    their average.

Q3. Write a program to print all prime numbers 

    that fall between two numbers(accept two 

    numbers from the user)

Q4. Write a program to display sum of odd numbers

    and even numbers that fall between 12 and 37

    (including both numbers)

Q5. Write a program to display all the numbers 

    which are divisible by 11 but not by 2 between

    100 and 500.

Q6. How many times the following loop execute?

c = 0

while c < 20:

           c += 2

Q7. Write the output of the following.

c = -9

while c < 20:

               c += 3

               print(c)

 

Q8. Write a program to print first 20 natural

    numbers except multiple of 2 & 3.

 

Q9. Write a program to print table of a number

    (accepted from user) in the following format.

    Like : input number is 7, so expected output  

    is

    7 * 1 = 7

    7 * 2 = 14 and so on

 

Q10. Write a program that keep on accepting number

     from the user until user enters Zero. 

     Display the sum and average of all the 

     numbers.

 

 

Python : Nested Loop Test 1

 

Python Nested Loop Test-1

Q1. Write a program to print the following pattern.

S. No

Pattern

Code

1.

1

1 1

1 1 1

1 1 1 1

1 1 1 1 1

 

 

2.

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

 

 

3.

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

 

 

4.

5

4 4

3 3 3

2 2 2 2

1 1 1 1 1

 

 

5.

5

5 4

5 4 3

5 4 3 2

5 4 3 2 1

 

 

6.

1

2 3

3 4 5

4 5 6 7

5 6 7 8 9

 

 

7.

1

2 1

3 2 1

4 3 2 1

5 4 3 2 1

 

 

8.

*

* *

* * *

* * * *

* * * * *

 

 

 

 

Solutions :

S. No

Pattern

Code

1.

1

1 1

1 1 1

1 1 1 1

1 1 1 1 1

 

2.

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

 

3.

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

 

4.

5

4 4

3 3 3

2 2 2 2

1 1 1 1 1

 

5.

5

5 4

5 4 3

5 4 3 2

5 4 3 2 1

 

6.

1

2 3

3 4 5

4 5 6 7

5 6 7 8 9

 

7.

1

2 1

3 2 1

4 3 2 1

5 4 3 2 1

 

8.

*

* *

* * *

* * * *

* * * * *

 

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet