The python code for printing a diamond pattern is :
def main():
n= input('The size of the diamond :: ')
a=n
for i in range(n):
print ' '*a,'*'*(2*i-1)
a=a-1
a=0
p=n
for i in range(n):
print ' '*a,'*'*(2*p-1)
a=a+1
p=p-1
main()
for a similar output the code in C is ::
#include<stdio.h>
int main()
{
int i,j;
int n;
printf("---PATTERN---\n");
printf("enter the number of rows :: \n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(" ");
}
for(j=0;j<2*i+1;j++)
{
printf("*");
}
printf("\n");
}
i=0;
for(i=0;i<=n;i++)
{
for(j=0;j<i;j++)
{
printf(" ");
}
for(j=2*n-1;j>=2*i-1;j--)
{
printf("*");
}
printf("\n");
}
return 0;
}
My Question is : Can we say that Mathematically the time complexity of the code in python is better than that of C? Although the Run time of the C program is less than that of Python but the same program in Python does not involve nesting of loops as in the case of C can we say that structurally Python is a more efficient language? -my apologies if the doubt sounds stupid.