Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your problem is simple, and has nothing to do with how you're passing values between functions.</p> <p>In <code>main</code>, you're reading a value from the user like this:</p> <pre><code>x=input("Enter the choice") </code></pre> <p>The <a href="http://docs.python.org/3/library/functions.html#input" rel="nofollow"><code>input</code></a> function:</p> <blockquote> <p>… reads a line from input, converts it to a string (stripping a trailing newline), and returns that.</p> </blockquote> <p>So, if the user types <code>1</code> at the prompt, you get back the string <code>"1"</code>.</p> <p>Now, you pass that value—perfectly correctly—to <code>menu</code>.</p> <p>In <code>menu</code>, you then try to compare it to various numbers, like this:</p> <pre><code>if x == 1: </code></pre> <p>But this will never be true. A string, like <code>"1"</code>, is <em>never</em> equal to a number, like <code>1</code>. They're not even the same <em>kind</em> of value, much less the same value.</p> <p>So, you need to do one of two things:</p> <ul> <li>Convert the input to an number. For example, change <code>menu(x,l)</code> to <code>menu(int(x), l)</code>. OR…</li> <li>Write <code>menu</code> to expect strings. For example, change <code>if x == 1:</code> to <code>if x == "1":</code>.</li> </ul> <hr> <p>You may be wondering why that <code>print (x)</code> didn't help you debug the problem.</p> <p><code>print(x)</code> prints out the end-user-friendly string representation of whatever you give it. That is, it automatically calls the <a href="http://docs.python.org/3/library/functions.html#func-str" rel="nofollow"><code>str</code></a> function for you. For debugging purposes, you often want to use <a href="http://docs.python.org/3/library/functions.html#repr" rel="nofollow"><code>repr</code></a> instead of <code>str</code>, to get the programmer-friendly string representation instead of the end-user-friendly string representation.</p> <p>For example, <code>print(str("10"))</code> will print out <code>10</code>—just like <code>print(str(10))</code>, so you can't tell them apart. But <code>print(repr("10"))</code> will print out <code>'10'</code>, unlike <code>print(repr(10))</code>, while prints <code>10</code>, so you <em>can</em> tell them apart. <code>repr</code> can also help you spot things like strings with invisible characters in them, having special "node" objects from a parser instead of just strings, etc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload