0% found this document useful (0 votes)
9 views

Python CIS 198

Python class activity

Uploaded by

Hi No
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python CIS 198

Python class activity

Uploaded by

Hi No
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Write a python program using For loop that print a right-angled triangle:
*

**

***

****

height = 5

for i in range(1, height + 1):

print("*" * i)

2. Write a python program using For loop that print a square pattern:

****

****

****

****

size = 4

for _ in range(size):

print("* " * size)

3. Write a python program using For loop that print a hollow square pattern:

*****

**

**

**
*****

size = 5
print('*' * size)

for i in range(size - 2):

print('*' + ' ' * (size - 2) + '*')

# Print

print('*' * size)

4. Write a python program using For loop that print a diamond pattern:

**

***

****

*****

****

***

**

n=5

# Upper half of the diamond

for i in range(n):

print(' ' * (n - i - 1) + '* ' * (i + 1))


# Lower half of the diamond

for i in range(n-1, 0, -1):

print(' ' * (n - i) + '* ' * i)


5. Write a python program using For loop that print a number pattern:

12

123

1234

12345

rows = 5

# outside

for i in range(1, rows + 1):

#inside

for j in range(1, i + 1):

print(j, end=" ")

You might also like