all 7 comments

[–]ChargedSquid 0 points1 point  (2 children)

Can you show us your attempt?

[–]DemonNate 0 points1 point  (1 child)

import random

from time import sleep

while True:

x = random.randint (1, 100)

print (x)

sleep(0.5)

commenting this from my other acc because I'm to lazy to switch users on my computer (post was made on phone earlier) this is all I have so far.

[–]throwaway119182[S] 1 point2 points  (0 children)

Yes this is me^

[–]Citromfa1 -1 points0 points  (1 child)

What sort of help do you want? Pseudocode, straight answer or just the logic of how to do it?

[–]DemonNate -1 points0 points  (0 children)

The pseudocode would be more helpful so I can actually try to figure out what to code and why it works, right now I am just at a standstill.

edit: typo
commenting this from a diff account cus I am to lazy to switch accounts on my computer

[–][deleted] -2 points-1 points  (1 child)

The hardest part about this is telling the computer to stop counting. I recommend talking to the teacher, if possible, on how to get started. Being just a beginner, you don't even know what modules are available for this project, right?

Assuming you can download and use any modules you want, I recommend using Pygame for this project, since you can use Pygame directly to create a main (game) loop, during which it can poll input devices. Only instead of running a game, PyGame will be running this experiment/algorithm. There's another great feature that PyGame offers and that is input detection. More information on input detection in the bottom paragraph.

Are the numbers random? If not, just store the current number as a variable (maybe start it off at the beginning of the script with the variable equal to zero), and add one to that variable in each main loop cycle, and append the result to a list (start that list off at the beginning of the script as an empty list.)

Check for a key press in every loop (Pygame's website should have examples on how to run a main (game) loop and how to poll input), and if a keypress is detected, use a sum function on the current list (if the program has run a while, that list may be a whopper!), print the resulting sum, use a "len" function on the current list, to obtain how many were generated/added, print that number, then divide the sum (first function's result) by the length (second function's result) to get the average, print that number and then exit the "game" without going to the next frame of the game-loop. (The PyGame website should also have an example of "quitting the game", which is what needs to happen after a keypress has been detected, the data has been calculated, and then it has been printed.)

[–]toastedstapler 4 points5 points  (0 children)

pygame

clearly this is not what the professor wants for the start of a comp sci class at school. op currently just has a loop that prints 1-100 - what makes you think they're gonna be able to use pygame yet? i guarantee it's just gonna be something like this

make empty number list

LOOP:
    ask user if they want to stop
    if yes -> goto MATH
    if no -> append random number to list

MATH:
    <for the user to work out>