Last active
December 24, 2015 02:09
-
-
Save JuniorPolegato/6728623 to your computer and use it in GitHub Desktop.
Gerar um losango dado um caracter e uma altura ímpar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
ESPACO = ' ' | |
caracter = raw_input("Caracter: ")[0] | |
altura = int(raw_input("Altura (ímpar maior ou igual a 3): ")) | |
if altura < 3 or altura % 2 == 0: | |
print "Altura precisa ser ímpar e maior ou igual a 3!" | |
sys.exit(0) | |
antes = (altura - 1) / 2 | |
print ESPACO * antes + caracter | |
dentro = 1 | |
sentido = -1 | |
antes += sentido | |
for a in range(1, altura - 1): | |
print ESPACO * antes + caracter + ESPACO * dentro + caracter | |
if not antes: | |
sentido = 1 | |
dentro -= sentido * 2 | |
antes += sentido | |
print ESPACO * antes + caracter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment