Kiran Vishwak
Kiran Vishwak

Reputation: 43

How do you accept multiple inputs and check whether it is a perfect square or not in Python without math?

lst=[]
n=int(input())
for i in range(0,n):
  ele=int(input("Enter: "))
  lst.append(ele)
for i in range(ele+1):
  power = i * i
  if power == ele:
    print("perfect sq")
  elif power > ele:
    print("not a perf sq")

I've tried a few things but got stuck here, while this worked for single input, it doesn't for multiple inputs.

Upvotes: 0

Views: 52

Answers (1)

mah111
mah111

Reputation: 146

If you're going mainly on user-inputs, then you can run a while loop until the user doesn't enter "Yes".

flag = True
while flag:
    lst = []
    n = int(input())
    for i in range(0, n):
        ele = int(input("Enter: "))
        lst.append(ele)
    for i in range(ele + 1):
        power = i * i
        if power == ele:
            print("perfect sq")
        elif power > ele:
            print("not a perf sq")
    temp = input("Continue? ")
    if temp != "Yes":
        flag = False

Upvotes: 1

Related Questions