I just started Python 2.7 very recently, but I\'m stuck at this a problem:
Make a program that prints an \"M\" pattern of asterisks. The user shall in
Limitation: Enter only old number greater than 3
Logic:
raw_input().3 only first line have 1 space, (ii) for input 5--> first line have space 3 and second line have space 1.for loop n time where n is user value.* at start and end according to for loop count.* according to user value.Code:
no = int (raw_input("Enter a number: "))
space_no = no - 2
print_line = "*"*no
for i in xrange(1,no+1):
if space_no>0:
print_line_n = "*"*i+" "*space_no+"*"*i
space_no -=2
print print_line_n
else:
print print_line
output:
vivek@vivek:~/Desktop/stackoverflow$ python 9.py
Enter a number: 3
* *
***
***
vivek@vivek:~/Desktop/stackoverflow$ python 9.py
Enter a number: 5
* *
** **
*****
*****
*****
vivek@vivek:~/Desktop/stackoverflow$ python 9.py
Enter a number: 9
* *
** **
*** ***
**** ****
*********
*********
*********
*********
*********
vivek@vivek:~/Desktop/stackoverflow$