﻿ Python Exercise: Print alphabet pattern S - w3resource

# Python Exercise: Print alphabet pattern S

## Python Conditional: Exercise - 26 with Solution

Write a Python program to print the following pattern 'S'.

Pictorial Presentation:

Sample Solution:

Python Code:

``````result_str="";
for row in range(0,7):
for column in range(0,7):
if (((row == 0 or row == 3 or row == 6) and column > 1 and column < 5) or (column == 1 and (row == 1 or row == 2 or row == 6)) or (column == 5 and (row == 0 or row == 4 or row == 5))):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);

row=15
col=18
result_str=""
for i in range(1,row+1):
if((i<=3)or(i>=7 and i<=9)or(i>=13 and i<=15)):
for j in range(1,col):
result_str=result_str+"o"
result_str=result_str+"\n"
elif(i>=4 and i<=6):
for j in range(1,5):
result_str=result_str+"o"
result_str=result_str+"\n"
else:
for j in range(1,14):
result_str=result_str+" "
for j in range(1,5):
result_str=result_str+"o"
result_str=result_str+"\n"
print(result_str);
```
```

Sample Output:

```  ****
*
*
***
*
*
****

ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
oooo
oooo
oooo
ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
oooo
oooo
oooo
ooooooooooooooooo
ooooooooooooooooo
ooooooooooooooooo
```

Flowchart Part-1:

Flowchart Part-2:

## Visualize Python code execution: Part - 1

The following tool visualize what the computer is doing step-by-step as it executes the said program:

## Visualize Python code execution: Part - 2

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Returns a list with n elements removed from the beginning

Example:

```def tips_take(itr, n = 1):
return itr[:n]
print(tips_take([1, 2, 3], 5))
print(tips_take([1, 2, 3], 0))
```

Output:

```[1, 2, 3]
[]
```