break-the-ice-with-python icon indicating copy to clipboard operation
break-the-ice-with-python copied to clipboard

Day 2 Question 9

Open Jugnupapa opened this issue 2 years ago • 1 comments

in this program every second string is being saved and every odd string is skipped.

Solution: change while input(): to while True: and it will be solved like below:

Why do every second line is storing in the list and all odd lines are skipped?

lst = []

while True: x = input() if len(x) != 0: lst.append(x.upper()) else: break

print(lst) for line in lst: print(line)

Jugnupapa avatar Dec 13 '22 10:12 Jugnupapa

I had the same problem. Neither of the provided solutions is correct.

Using the not equals operator allows the user to enter blank lines as shown in the solution.

lines = []
print("Enter your text, when finished type 'end_and_print':\n")
while True:
    line = input()
    if line != 'end_and_print':
        lines.append(line)
    else:
        break
print('\n'.join(lines).upper())

Euan-J-Austin avatar Feb 28 '23 20:02 Euan-J-Austin