Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Python3 no longer supports print as a special form with the arguments following the print keyword (like <code>print x</code> in Python 2.x). Instead <code>print</code> is now a function and requires an argument list like in: <code>print(x)</code>. See "Print is a function" in <a href="http://docs.python.org/release/3.0.1/whatsnew/3.0.html" rel="nofollow">http://docs.python.org/release/3.0.1/whatsnew/3.0.html</a></p> <p>In addition the <code>break</code> statement cannot occur outside of a loop. Other than the C <code>switch</code> statement, <code>if</code> does not support break. As there is no fall-through logic for if-statements it is not requred. In order to stop execution of the function and return to the caller use <code>return</code>.</p> <p>Instead of the <code>is</code> operator, use the equality operator <code>==</code>. <code>is</code> tests if objects are identical, this is a stricter test than equality. More details can be found <a href="http://docs.python.org/reference/datamodel.html#object.__hash__" rel="nofollow">here</a>.</p> <p>In addition you are getting the weight as a string. You might want to convert the string to an integer for comparison with other integer values, using the function <code>int(weight)</code>.</p> <p>Also there are a number of other small errors: </p> <ul> <li>You are assigning the user input for the weight to <code>e</code> while you try to use the undefined variable name <code>w</code> in the function call</li> <li>The first parameter in the function is called <code>texture</code> but you are using <code>textura</code> in the function body.</li> <li>You are using <code>peso</code> instead of <code>weight</code> in one instance</li> </ul> <p>Here is a (less offensive) rewrite with those errors eliminated:</p> <pre><code>def stuff(color, weight): color_txt = "Your stuff is " if color == "green": color_txt += "green as an apple" elif color == "blue": color_txt += "blue as the sky" elif color == "purple": color_txt += "purple as an eggplant" else: print("Invalid color!") return w = 0 # converting a string to an integer might # throw an exception if the input is invalid try: w = int(weight) except ValueError: print("Invalid weight!") return weight_txt = "" if w&lt;20: weight_txt = " and weighs so few" elif 20 &lt;= w &lt;= 50: weight_txt = " and weighs mid" elif w &gt; 50: weight_txt = " and weighs a lot" else: print("Invalid weight!") return color_txt + weight_txt c = input("Input color: ") w = input("Input weight: ") r = stuff(c, w) print(r) </code></pre>
 

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