简体   繁体   English

您如何在没有数学的情况下接受多个输入并检查它是否是 Python 中的完美正方形?

[英]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" .如果您主要使用用户输入,那么您可以运行一个 while 循环,直到用户不输入"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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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