0

For instance,

while True:
    variable_a = input()

So, this while loop will keep asking for input.

If I want the first input from users be stored in "variable_a", and the second input be stored in a different variable, let say "variable_b". What should I do without using two input() statements?

Actually I want to compare these two inputs. Like this

if variable_a == variable_b: 
    print("Yes")

But I don't know how to do that with only one input() statement.

y007s
  • 1
  • 2
  • 2
    When choosing between clear and clever, go with clear. Unless you have a very specific reason not to use two input statements, you should use two input statements. If there's an arbitrary number of user inputs, could you please provide more info about the problem you're trying to solve? – Unknown artist Sep 22 '20 at 15:12
  • So you want to have only one line with `input()` but compare two of its outputs? You could easily do that with a list, why can't you? As for using two variables, the second time around on the loop you could check if one already has contents, then copy its value to another variable and reuse the original one to get the next input, then compare the two at the end - that sounds like what you're asking, but again without knowing why you need what you need, I can't be sure that's the right solution for your issue. It seems unnecessarily complicated and abnormal. – Random Davis Sep 22 '20 at 15:13
  • 1
    Canonical: https://stackoverflow.com/q/1373164/3001761 – jonrsharpe Sep 22 '20 at 15:14
  • Actually my problem is to write a program for the user to input a character line by line. If the character is the same with the last one, then count the number of occurrences until a new character appears. For example, a,a,b,b,a, -> the output should be a,2,b,2,a,1. And I've tried using two input statements, but it doesn't work, because it only processes when the first and second variable is different. If i type a,a,b, it doesn't process. Only a,b works. – y007s Sep 22 '20 at 15:22
  • @y007s Your current question is totaly different, maybe is better to update it so we can help you? The comment you wrote require another thing, so provide your code and clarify the question. – Carlo Zanocco Sep 22 '20 at 15:37

2 Answers2

0

If you are comparing an incoming value to a previous one in an infinite loop, you can have an implementation that is aware of those states (like "current" and "previous"). For example:

previous = None
while True:
    current = input()
    if current == previous:
         # continue counting
    else:
         # do something else
    previous = current # shift value to 'previous' for the next cycle
Unknown artist
  • 947
  • 9
  • 14
-2

It is only possible if you use:- . Array .Sets or tuples or .String:Store the variables in a string string=string+space+character inside a loop. And then seperate them through spaces between them.* The string one is the way you could do.

Arya
  • 1
  • 4