Python 中的完美平方元组函数检查器(布尔)赋值

问题描述 投票:0回答:1

我必须编写这个返回 true 或 false 的函数:它是一个 check_perfect_squares() 函数,参数是 tups 和包含数字的元组列表。每个的长度是 2。如果它们是,它将返回 true,如果它们不是,它将返回 false 我不知道这是一个愚蠢的问题,但我似乎无法弄清楚为什么我的函数对于我的任何示例案例都不返回任何内容:

import math
from typing import List, Tuple
def check_perfect_squares(tups: List[Tuple[int, int]]) -> bool:
    for tup in tups:
        if tup[0] * tup[0] != tup[1]:
            return False
    return True

check_perfect_squares([(2,4)])

当我将元组输入 check_perfect_squares() 时它应该可以工作

python python-3.x function tuples perfect
1个回答
0
投票

你的函数确实返回了一些东西,但是缺少打印语句意味着你看不到结果。

© www.soinside.com 2019 - 2024. All rights reserved.