Python Forum

Full Version: from 50 random numbers printing only the sqrt(...)==0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey i need to write a program to school and im new to python so im trying different things.
I need to choose 50 random numbers from interval f.e. from 100 random numbers and do number**0.5 and i need it to output the whole numbers that are int after finishing = 25**0.5=5
i have this but honestly its bad af or idk
import random
def main():
    for i in range(50):
        list=random.randint(1,100)
a =[list]
for i in a:
    if i**(0.5)==0:
        print(i)
I dont know what to do because we have like teacher that doesnt know it either so i dont know
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

First, don't name a variable list. The word list has meaning in python, and if you use it as a variable name, you lose access to that, and so does other code that may depend on it.

On line 4, you assign a random number to list. Fifty times you do this, and every time you are writing over the last one you did. So at the end, list is just a random number, and the variable 'a' only has one number in it. You want to initialize the list, and then append to it in the loop:

numbers = []
for number in range(50):
    numbers.append(random.randint(1, 100)