Test yourself - While loops



Try some exercises on while loops.

1.  Consider an integer input n=4351687546. Start from the last, Display the digit if it is greater than or equal to 5 else, print a '*'. 


Example:

if n=43587- your output should be '7 8 5 * *'.

2. **Placement problem : Try to code bubble sort in python using while loop. Display each iteration's output. 


3. Print the patterns given below. Try to find the appropriate condition for while loops.


a.           *****

              ****
              ***
              **
              *


b.         1

            00
            111
            0000
            11111
            000000

4.  Rotate the given array in right for n times. let 'n' be the user input. For example :

if arr= [1,2,3,4,5]
no.of.rotations=2
output=[4,5,1,2,3]

Now try rotating the array in the right side - arr=[4,6,7,2,5,1,9,33]. Try for different number of rotations. For example :

input: [1,2,3,4,5]

no.of.rotations: 2
output: [4,5,1,2,3]

5.  We all know that we can use some polite words in the place of words such as blind,deaf, etc,. Now a paragraph is given and dictionary with suitable alternatives is given. Use appropriate methods and replace all the offensive methods with their alternatives in the dictionary. Reconstruct the paragraph after replacing words. 

dictionary : 

dict1={'blind':'visually challenged','handicapped':'differently abled','deaf':'hearing impaired','mentally-retarded':'special child'}

paragraph :

para1="Now-a-days people who are even blind achieve something.Marla Runyan is the first blind athlete in the olympics.Mariyappan Thangavelu won gold medal in high jump in paralympics.He was a handicapped.Ludwig Van Beethoven, the greatest classical composer ever was a deaf."

Comments