I’m sure this one is going to be simple and it might just be a little late in the day for my brain to fully function, but my question is the title. How can I compare two strings but using the same variable in a loop? I realize the way its set up now it always going to break the loop. Do I have to use two variables.? One way I can think of is maybe have a count variable? Haven’t fleshed out that idea.
What I am trying to do is break when the same string is entered in 2 times in a row.
word = "" story = "" while True: word = str(input("Please type in a word:")) story += word + " " if word == word: break elif word == "exit": break print (story)
submitted by /u/FeedMeAStrayCat
[link] [comments]
r/learnpython I’m sure this one is going to be simple and it might just be a little late in the day for my brain to fully function, but my question is the title. How can I compare two strings but using the same variable in a loop? I realize the way its set up now it always going to break the loop. Do I have to use two variables.? One way I can think of is maybe have a count variable? Haven’t fleshed out that idea. What I am trying to do is break when the same string is entered in 2 times in a row. word = “” story = “” while True: word = str(input(“Please type in a word:”)) story += word + ” ” if word == word: break elif word == “exit”: break print (story) submitted by /u/FeedMeAStrayCat [link] [comments]
I’m sure this one is going to be simple and it might just be a little late in the day for my brain to fully function, but my question is the title. How can I compare two strings but using the same variable in a loop? I realize the way its set up now it always going to break the loop. Do I have to use two variables.? One way I can think of is maybe have a count variable? Haven’t fleshed out that idea.
What I am trying to do is break when the same string is entered in 2 times in a row.
word = "" story = "" while True: word = str(input("Please type in a word:")) story += word + " " if word == word: break elif word == "exit": break print (story)
submitted by /u/FeedMeAStrayCat
[link] [comments]