Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 2 Question 9 #127

Open
Jugnupapa opened this issue Dec 13, 2022 · 1 comment
Open

Day 2 Question 9 #127

Jugnupapa opened this issue Dec 13, 2022 · 1 comment

Comments

@Jugnupapa
Copy link

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)

@Euan-J-Austin
Copy link

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants