CSC111 Exercises on nested for-loops

From dftwiki3
Revision as of 10:33, 24 February 2014 by Thiebaut (talk | contribs) (Exercise 1)
Jump to: navigation, search

--D. Thiebaut (talk) 10:32, 24 February 2014 (EST)


Exercise 1


This is taken from Section 4.7 in the textbook:

for i in range(4):
   for j in range( i+1 ):
      print( "*", end="" )
   print()


The output is

 *
 **
 ***
 ****


Question
Modify the program so that it outputs this pattern


 ****
 ***
 **
 *


Exercise 2


Modify the program so that it outputs this pattern:

    *
   **
  *** 
 ****