Hi
I receive incorrect printout when running this code? What is wrong?
Here is my code;
numbers = [5, 2, 5, 2, 2]
for x_count in numbers:
output = ‘’
for count in range(x_count):
output += ‘x’
print(output)
I receive:
x
xx
xxx
xxxx
xxxxx
x
xx
x
xx
xxx
xxxx
xxxxx
x
xx
x
xx
Hello wardffrank,
What result are you expecting?
Your code loops through your numbers list.
For each iteration you set output to ‘’
For each iteration in the list you create a new for-loop in which you loop x_count times (the number youre currently iterating over from your numbers-list). You add an x in every iteration to output and print it to the terminal.
Hello thanks for responding. I want the output to be the letter F made by “x”.
Like this;
xxxxx
xx
xxxxx
xx
xx
numbers = [5, 2, 5, 2, 2]
for number in numbers:
print("x" * number)