Python Forum
from 50 random numbers printing only the sqrt(...)==0
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from 50 random numbers printing only the sqrt(...)==0
#1
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
Reply
#2
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)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  random numbers, randint janeik 2 526 Nov-27-2023, 05:17 PM
Last Post: janeik
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,012 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,531 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,428 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Random nr. no repetition & printing multiple lines Joey 7 2,736 Feb-05-2020, 04:23 PM
Last Post: Larz60+
  output a list of random numbers 'x' columns wide adityavpratap 4 2,922 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Can i prevent the random generator to generate already used numbers? MauserMan 3 2,804 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Working with Random Generated Numbers YoungGrassHopper 4 3,138 Sep-10-2019, 06:53 AM
Last Post: YoungGrassHopper
  Need to generate random numbers Gateux 8 3,866 Jul-19-2019, 03:37 PM
Last Post: Man_from_India
  custom sqrt bluefrog 4 3,053 Jul-14-2019, 08:49 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020