Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have just had browse through your code, and while you probably have it figured out now I thought a few suggestions might help you get more into python.</p> <p>Firstly, style is really important with python, being a white space language. The language also has some great features that can condense the amount of code down, which again encourages a good style. There is something called PEP guides, which introduce this. <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP-8</a> is the style guide for python, I would highly recommend reading through it, if you are getting more into python.</p> <p>Also when I was learning python I found this <a href="http://sheddingbikes.com/LearnPythonTheHardWay.pdf" rel="nofollow">learning python the hard way guide</a> an excellent resource. Python is really fun when you get into, hope you're enjoying it! Below is another version of your code that might make more sense. </p> <pre><code>import random # All imports should be at the top, if you know # you are going to use them. def menu(): print("Menu:") print(" 0. Menu") print(" 1. Random Number Generator") access = int(input("Make a selection from the above list: ")) return access # See explanation access = menu() # See explanation if access == 1: count = 0 b = 0 while count &lt; 100: count += 1 a = random.randrange(1,101) print(count,". ", a, end = " | " ) b += a print() print("Finish!") print(b) print(b/100) menu() else: menu() </code></pre> <p>**Explanation: It is important to store the value of access into a variable here. You cannot set a value inside a function and expect it to update for the rest of the script. This is because of scoping. </p> <p>**Also if you are expecting the menu to be called again every time after a selection has been executed you while need to rethink the structure somewhat.</p> <p>Another way of doing this is to use a for loop. To do this you would having something like:</p> <pre><code> for i in range(100): a = random.randrange(1,101) print(count,". ", a, end = " | " ) b += a print() print("Finish!") print(b) print(b/100) menu() </code></pre>
    singulars
    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. 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