Share your repls and programming experiences

← Back to all posts
Rectangle Drawer
ChandlerMorell (78)

The tutorial is within the comments of the code! I encourage you to play around with it!

Comments
hotnewtop
kaldisberzins (344)

Nice turorial! Easy to understand for a person who barely knows cpp like me.

ChandlerMorell (78)

@kaldisberzins Thank you very much! I am glad you got something out of it!

[deleted]

This is very cool! Nice job! You get my like

ChandlerMorell (78)

@IEATPYTHON Thank you very much! I thought this would be the perfect for loop example for a beginner. I'm clean out of ideas though. I want to make another one.

ChandlerMorell (78)

@IEATPYTHON By the way, I am a huge fan of your Advanced Text Reverser. Haha.

[deleted]

@ChandlerMorell Oh that is not mine it is just a fork. BTW can you please check my tutorial out. Mine is the working memory one

ChandlerMorell (78)

@IEATPYTHON You should make one of these in Python. After that, eat it, of course. :)

[deleted]

@ChandlerMorell Make what in python?

ChandlerMorell (78)

@IEATPYTHON Rectangle drawer. Or a shape drawer in general.

EdwardWarren (0)

@ChandlerMorell

def enter_width_height():
print()
print("Enter width and height separated by space:")
print()
M=lambda: list(map(int, input().split()))
return M()

def print_square_or_rectangle(width,height):
print()
side=str(' '+' '(width-2)+'')
topbot='
'*width
print(topbot)
for i in range(height-2):
print(side)
print(topbot)
print()

def print_description(f_width,f_height):
if f_width == f_height:
print("This is a ", f_width, "x", f_height, " unit square!")
print("\nArea:", f_width f_width)
print("Perimeter: ", f_width
4)
else:
print("This is a ", f_width, "x", f_height, " rectangle!")
print("\nArea:", f_width f_height)
print("Perimeter: ", 2
f_width + f_height)

width,height = enter_width_height()
print_square_or_rectangle(width,height)
print_description(width,height)

ChandlerMorell (78)

@EdwardWarren Didn't work for me. I don't know why.. Does is draw a rectangle? Like my C++ program?

XavierDD (90)

Nice tutorial, its easy to read and not to complicated.

2IsAPrimeNumber (26)

If I enter one negative number, the area will be negative, the perimeter will be 0, and no rectangle will be drawn. If I enter two negative numbers, the area will be positive, the perimeter will be (2 width + 2 height), and no rectangle will be drawn. If the width contains a decimal, the program will stop, the area will be 0, and the perimeter will be (2 * width rounded down), and no rectangle will be drawn. If the height contains a decimal, the program will round the height down, and continue the repl as if two integers were given.

2IsAPrimeNumber (26)

In sum, the program only runs correctly when two non-negative integers are given.

ChandlerMorell (78)

@2IsAPrimeNumber Yes, that is correct. I used ints instead of doubles, because you can't have a fraction of an asterisk. You also can't have a negative length/width rectangle. I suppose I could make a warning for it. Hope this helps!

2IsAPrimeNumber (26)

@ChandlerMorell I don't know what an "asterisk" is.