Friday 22 February 2019

How to let the user input as many lines of input as they want until they input the "stop" word in Python?

Say that I'm asking the user to input lines from a book or whatever. I don't know how many lines they will decide to input though. How would you let them input as many lines as they want until they input a secret word, "blueblue" for example. That's the code i've got so far.



while (blueblue == false):
line1 = input()



Help would be much appreciated.



Hey, after using Owen's code i'm having a problem with reading and outputing some info. I'd like to ask it here instead of opening another question. Here's my code now:



lines = []
current_line = input()
while current_line != "blueblue":
lines.append(current_line)
current_line = input()
print (lines)

ints_list = []
for line_ in lines:
for letter in line:
if (letter == "0","1","2","3","4","5","6","7","8","9"):
print ("hueheuheuehheuue")


Now Say that user input is :



1 hello my name

is cmput 3.4


It will just print "huehueheuheu" the number of characters there are in the while input.
I've tried the number without brackets and still deson't work, i've even tried "or".
Please help.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...