 <p>Here, I am storing all the names ending with 'x' in <code>namex_list</code> instead of using the <code>list</code>(also a built-in variable) variable you used before.</p> <p>Also, i am assigning <code>namex_list</code> as an empty list before the while condition and printing the <code>namex_list</code> at the end outside of <code>while</code>.</p> <pre><code>namex_list = [] while True: name = input("Enter your name: ") if name == "": break if name.endswith("x"): namex_list.append(name) print (namex_list) </code></pre> <p>Also, <code>name == namex</code> does not check what you are trying to achieve because of the comparison between string values and boolean values.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; name1 = 'abc' &gt;&gt;&gt; name2 = 'abcx' &gt;&gt;&gt; namex1 = name1.endswith('x') &gt;&gt;&gt; namex2 = name2.endswith('x') &gt;&gt;&gt; namex1 False &gt;&gt;&gt; namex2 True &gt;&gt;&gt; name1 == namex1 False &gt;&gt;&gt; name2 == namex2 False </code></pre> <p>You should use an <code>if</code> instead to achieve what you are trying to achieve in your code above:</p> <pre><code>if name.endswith("x"): </code></pre>