简体   繁体   English

知道为什么hackerrank 不接受我的代码,即使它准确打印了要求的内容

[英]Any idea why hackerrank doesn't accept my code even if it prints exactly what is asked

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n Here is the exact question from hackerrank:楼梯右对齐,由# 符号和空格组成,高度和宽度为 n 以下是来自hackerrank的确切问题:
https://www.hackerrank.com/challenges/staircase/problem https://www.hackerrank.com/challenges/staircase/problem

And here is my code:这是我的代码:

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the staircase function below.
def staircase(n):
    for i in range(-1,n):
        print(n*' ' + (i+1)*'#')
        n=n-1

if __name__ == '__main__':
    n = int(input())

    staircase(n)

If you are using python3: Try following for the same problem (All test cases should pass):如果您使用的是 python3:请尝试针对同一问题执行以下操作(所有测试用例都应通过):

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the staircase function below.
def staircase(n):
    num = n
    for i in range(1,n+1):
        space = num-i
        if space==0:
            print("#"*i)
        else:
            print(' ' * (space-1), "#"*i)

if __name__ == '__main__':
    n = int(input())
    staircase(n)

You have an extra line of spaces on the top Try this-顶部有一行额外的空格 试试这个-

import math
import os
import random
import re
import sys

# Complete the staircase function below.
def staircase(n):
    for x in range(1,n+1):
        print((n-x)*" "+"#"*x)

if __name__ == '__main__':
    n = int(input())

    staircase(n)

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

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