如何在python中找到一个特殊的pascals三角形行?

时间:2016-09-13 13:19:09

标签: python python-3.x pascals-triangle

这是我的代码的快照,用于将最多n行的pascal三角形写入名为“ pascalrow.txt ”的文件中,之后它将行号作为输入,如果该行找到后,它会重新打开文件,找到行号并显示整行。

它有点工作但是......一旦我移动到9行以上,那么我将返回无

例如:我tried this并且按预期完美运行。 但后来I tried doing this我吓坏了。在第二张图片中,可以看到第9行以上的任何内容,我作为输入,它返回我没有。顺便说一下,我用过文件因为我不想多想怎么回事,因为我感觉真的很懒。无论如何,任何人都可以帮助我理解为什么它的发生和可能的解决方案? :3

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Redirecting you to *The Website*</title>
    <link rel="canonical" href="<Your website>" />
</head>
<?php
# The code below will redirect the users to the site that you want to redirect to.
# If the site has HTTPs, please change the "http://" to "https://"
header('Location: http://*Where you want the users to be redirected to*/');
exit();
# The "exit" code will prevent any more redirects in the current page.
?>
</html>

1 个答案:

答案 0 :(得分:1)

你的代码工作的事实是惊人的。

您将一个弦乐列表写入文件中的一行,然后读取该文件并逐个字符地查看该行。所以,通过一个奇迹,你会发现第8行,因为你找到的前8个是'[1,8,28 ...]中的一个字符。当然,它不能用于行,例如6,以及9以上的任何东西(因为'10'将不匹配任何角色。)

所以,转储所有文件废话,然后写:

a = pascal(n)