Full Pyramid


This is a companion discussion topic for the original entry at https://toph.co/p/full-pyramid

What is the problem in my code.

a=int(input())
for i in range(a):
    for j in range(a-i-1):
        print(end=" ")
    for j in range(i+1):
        print("*",end=' ')
    print()

@Soudip the problem is the extra space you are printing after each line.
Try to avoid doing it.

You can change as below:

    for k in range(i+1):

        print('*',end= '')
        if k< i:
            print(' ',end = '')
    print()

`

`

  • what is the python answer??

#include<stdio.h>

int main()
{
int n;
scanf("%d",&n);
int r=n;
for(int i=1; i<=r;i++){
for(int j=1; j<=n;j++){
printf(" “);
}
n–;
for(int k=1; k<=i;k++){
printf(” *");
}
printf("\n");
}
return 0;
}

What is the problem in this code ,?

@Mohammad.Ali Read the problem statement carefully. Your output is incorrect. You can test your output in udebug here and test what is wrong in your output.

The problem is, you are not printing the spaces between asterisks which is shown in the sample test cases. for example for the input

3

The output should be

  *
 * *
* * *

But your output is

  *
 **
***

Which is crealy incorrect.

Screenshot%20(136)
but here it show it is working … can you please give me the reason of it ?

Sorry @Mohammad.Ali, it was a mistake from me.

Normally when submissions for this kind of problems does not work, it is for a silly mistake. So, I thought it was something identical here.

I read your code in a hurry and mistook " *" with "*". And so, I thought that you forgot to put space in there.

I didn’t even bother to run your code like I do, usually.

However, I properly run your code here and tested the output it in uDebug. Here is what I got.

Ali

It seems to be that you are printing 2 unnecessary spaces in front of every single line.

It was something silly after all, you should have tested the output of your code in uDebug here. That’s probably the reason why you are getting a Wrong Answer.
Fix it and your code should be accepted.

And please don’t share screenshots of your code. If want to show the output, you can use ideone.

1 Like
a=int(input())
for i in range(1,a+1):
    for j in range(a-i):
        print(end = " ")
    for star in range(i):
        print("*", end =" ")
    print()

Where is my problem?

@corrupted_brain, at least try to read previous posts before posting your problem. You are printing an extra space at the end of every line, fix it and it will do.

Thank you brother , now it is working

Can you please tell me where is the problem in my code:

    #include <iostream>
using namespace std;
int main()
{
int i, n, x;
cin >> n;
for(i=1; i<=n; i++){
    for(x=0;x<(n-i);x++){
        cout << " ";
    }
    for(x=i;x>0;x--){
        cout << "*" << " ";
    }
    cout << "\n";
}

return 0;
}

It says wrong. but i compiled it in codeblocks:
Untitled

Extra space at the end of every line.
You should read previous posts before you post @Aiden_Pirace.
You can find the answer to your question without even asking that way.
Cause people tend to do the same mistakes.

1 Like

Where am I putting up the extra space? I have tried a lot, at least all the patterns for this problem, but nothing seems to work in toph,

#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int r=n;
for(int i=1; i<=r;i++){
    for(int j=1; j<=n;j++){
        printf(" ");
        }
        n--;
    for(int k=1; k<=i;k++){
        printf("* ");
    }
    printf("\n");
}
return 0;
}

@iker_13 :zipper_mouth_face:
in front as well as the end of every line. :expressionless:

Please help me to find the problem.

#include<stdio.h>
int main()
{
    int a,i,j,k,l;
    scanf("%d",&a);
    k=a-1;
    l=k;

    for(i=0;i<a;i++,k--,l--){
        for(;k>0;k--){
            printf(" ");
        }

        for(j=0;j<=i;j++){

            printf("* ");
        }
        printf("\n");
        k=l;
    }
    return 0;
}

i got solution

[REDACTED]

#include<stdio.h>
int main()
{
int i, j, k, n;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n - i; j++)
printf(" “);
for (k = 0; k <= i; k++)
{
printf(”*");
if (k!=i)
printf(" “);
}
if (i!=n-1)
printf(”\n");
}
return 0;
}
Why wrong answer?