Bottom Page

Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 from 50 random numbers printing only the sqrt(...)==0
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):
a =[list]
for i in a:
    if i**(0.5)==0:
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)
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Printing lists acooper7 1 88 Jun-17-2019, 09:37 PM
Last Post: Yoriz
  Subtract value from random dictionary key:value Tolein 1 58 Jun-12-2019, 02:02 PM
Last Post: perfringo
  Unique Random ID on Table talius 2 107 May-30-2019, 01:47 PM
Last Post: michalmonday
  Printing List in one line bharat_s579 6 211 May-26-2019, 08:30 PM
Last Post: perfringo
  Generate unique random numbers from different lists Takeshio 5 160 May-24-2019, 07:29 PM
Last Post: ichabod801
  list is printing incorrectly.. anna 1 115 May-18-2019, 12:12 PM
Last Post: ichabod801
  Multiple Random Selections with no dulpicates forrester 2 103 May-11-2019, 06:41 AM
Last Post: perfringo
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 135 May-09-2019, 12:19 PM
Last Post: Pleiades
  help cant do random number nonzzo 1 128 Mar-28-2019, 07:33 PM
Last Post: Yoriz
  Print random musik to wav file Pereskia 2 157 Mar-27-2019, 11:53 AM
Last Post: Pereskia

Forum Jump:

Users browsing this thread: 1 Guest(s)