-3
Is there any way to optimize the code below? I feel like I used many "Fors".
texto = ''
num = 10
for c in range(1, num):
linha = ''
for v in range(1, num - c):
linha += ' '
linha += '/'
for g in range(1, c*2-1):
linha += ' '
linha += '\\'
texto += linha + '\n'
print(texto)
Output:
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
We don’t even know what the code should do. Or the criteria. There is a way that is extremely optimized, just print the result without doing any processing, gives the same result.
– Maniero
All lines are equal, what changes is the amount of spaces before the
/
, between the bars and after the\\
. If you parameterize this by making the solution more generic, your solution will be more optimized. Good luck.– Woss
Optimized not to use for:
print(" /\\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n/ \\")
- See working here: IDEONE– Bacco