I need to write a function which has 2 parameters height and width and outputs a rectangle of "#" ssmbol of the appropriate dimensions. so for 93, 4) should result in the output
####
####
####

but i dnt unserstand how to use the loop in this. I have only done loops once til nw and i tried using that code for this one but i get error everytime, probably coz the whole code is wrong. This is my first code i did using loop which is correct. But i cant seem to know how to do the second one?. I know the code i have done for the second one is not very much and probably wrong, If you guys could atleast provide me with a example it would do, if you think i am asking you to do the h/w for me thing..

word=raw_input("please enter the word for the song :")
repeat=input("how many times should the song be repeated? :")
lines=input("how many lines should the song be for? :")
for i in range(lines):
     print word*repeat
def drawBlock(height, width):
    x="#"
    for i in range(drawBlock):
     print x

Recommended Answers

All 3 Replies

Member Avatar for masterofpuppets

try this:

>>> w = 4
>>> h = 3
>>> for i in range( h ):
	print w * "# "

	
# # # # 
# # # # 
# # # # 
>>>
Member Avatar for masterofpuppets

just wrap that up in a function :)

jaison2, range(drawBlock) in your code does not make any sense, since range() expects an integer value. In your loop you want something like this ...

for row in range(height):
    # multiplier will give width number of '#' characters
    print '#' * width
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.