Bottom Page

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
Quote
#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

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  list is printing incorrectly.. anna 1 65 May-18-2019, 12:12 PM
Last Post: ichabod801
  Multiple Random Selections with no dulpicates forrester 2 65 May-11-2019, 06:41 AM
Last Post: perfringo
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 75 May-09-2019, 12:19 PM
Last Post: Pleiades
  help cant do random number nonzzo 1 92 Mar-28-2019, 07:33 PM
Last Post: Yoriz
  Print random musik to wav file Pereskia 2 117 Mar-27-2019, 11:53 AM
Last Post: Pereskia
  random.randrange ravioli2929 14 404 Mar-17-2019, 04:49 PM
Last Post: perfringo
  Question about the Random Module Exsul 1 100 Mar-13-2019, 02:06 AM
Last Post: ichabod801
  Random function sh98765 1 109 Mar-11-2019, 02:08 AM
Last Post: ichabod801
  no outcome is printing helpme 2 135 Mar-07-2019, 02:15 PM
Last Post: helpme
  Printing Easter date occurrences samsonite 8 268 Mar-06-2019, 11:49 AM
Last Post: samsonite

Forum Jump:


Users browsing this thread: 1 Guest(s)