-6

I am not even sure how to start. could anyone help me to write a code?

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
Minto
  • 1
  • 1
  • this must be a homework assignment ... see also:http://stackoverflow.com/questions/40390902/python-is-there-a-builtin-that-works-similar-but-opposite-to-index – Joran Beasley Nov 03 '16 at 00:03
  • 1
    as an aside usually where you start is asking your professor or classmates for help ... (and making it to all the lectures) – Joran Beasley Nov 03 '16 at 00:07
  • This seems more like a math question than programming. Once you find out the mathematical process, coding it in Python should be obvious. – Barmar Nov 03 '16 at 00:28

1 Answers1

0

You are obviously a begginer, so I will explain the code. Say we have a list with numbers 1,5,7,9 and 16.

mylist = [1,5,7,9,16]

Now we have to search through our numbers to find if they are squares.

for number in mylist:
    if math.sqrt(number)**2 == number:
        print(str(number) + " is a square number")

If you just run this code as is, it will output "Error: Math is not defined", you have to allow access to the math module. To do this, at the top of your code type:

import math

Now you can run it and it will output:

1 is a square number
9 is a square number
16 is a square number
Lachlan Mather
  • 135
  • 2
  • 5
  • 14