简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM