Python Pattern and String
Python Pattern and String
Pattern #11: Connected Inverted Pyramid Pattern Pattern #12: Even Number Pyramid Pattern
of Numbers rows = 5
rows = 6 LastEvenNumber = 2 * rows
for i in range(0, rows): evenNumber = LastEvenNumber
for j in range(rows – 1, i, -1): for i in range(1, rows+1):
print(j, ”, end=”) evenNumber = LastEvenNumber
for l in range(i): for j in range(i):
print(‘ ‘, end=”) print(evenNumber, end=’ ‘)
for k in range(i + 1, rows): evenNumber -= 2
print(k, ”, end=”) print(“\r”)
print(‘\n’)
Pattern #13: Pyramid of Horizontal Tables Pattern #14: Pyramid Pattern of Alternate Numbers
rows = 7 rows = 5
for i in range(0, rows): i=1
for j in range(0, i + 1): while i <= rows:
print(i * j, end=’ ‘) j=1
print() while j <= i:
print((i * 2 – 1), end=” “)
j=j+1
i=i+1
print()
Pattern #15: Mirrored Pyramid (Right-angled Pattern #16: Equilateral Triangle with Stars (Asterisk
Triangle) Pattern of Numbers Symbol)
Pattern: print(“Print equilateral triangle Pyramid using stars
rows = 6 “)
for row in range(1, rows): size = 7
num = 1 m = (2 * size) – 2
for j in range(rows, 0, -1): for i in range(0, size):
if j > row: for j in range(0, m):
print(” “, end=’ ‘) print(end=” “)
else: m = m – 1 # decrementing m after each loop
print(num, end=’ ‘) for j in range(0, i + 1):
num += 1 # printing full Triangle pyramid using stars
print(“”) print(“* “, end=’ ‘)
print(” “)
Pattern #17: Downward Triangle Pattern of Stars Pattern #18: Pyramid Pattern of Stars
rows = 5 rows = 5
k = 2 * rows – 2 for i in range(0, rows):
for i in range(rows, -1, -1): for j in range(0, i + 1):
for j in range(k, 0, -1): print(“*”, end=’ ‘)
print(end=” “) print(“\r”)
k=k+1
for j in range(0, i + 1):
print(“*”, end=” “)
print(“”)
# vowel alphabet
vowel =
'A','E','I','O','U','a','e','i',
'o','u'
# Function to check
def check(string):
if (Vowel(string)):
print('Accept')
else:
print('Not Accept')
# take input
character = input('Enter the
String: ')
# take input
string = input('Enter any
string: ')
# calling function
countVowels(string)
# Python program to remove all # Python program to remove all
vowels from string vowels from string
if __name__ == "__main__":
input = 'geeks quiz
practice code'
print
(rev_sentence(input))
# Python program to capitalize # Python program to accept the strings
# first and last character of # which contains all the vowels
# each word of a String # Function for check if string
# Function to do the same # is accepted or not
def word_both_cap(str): def check(string) :
#lamda function for string = string.lower()
capitalizing the
vowels = set("aeiou")
# first and last letter of
s = set({})
words in
# the string return # looping through each
' '.join(map(lambda s: s[:- # character of the string
1]+s[-1].upper(), for char in string :
s.title().split())) if char in vowels :
# Driver's code s.add(char)
s = "welcome to eeksforgeeks" else
print("String before:", s) pass
print("String after:", # accepted otherwise not
word_both_cap(str)) if len(s) == len(vowels)
print("Accepted")
else :
print("Not Accepted")
# Driver code
if __name__ == "__main__" :
string = "SEEquoiaL"
# calling function
check(string)
def check(string): import re
string = string.replace(' sampleInput = "aeioAEiuioea"
', '') # regular expression to find the strings
string = string.lower() # which have characters other than a,e,i,o and
vowel = u
[string.count('a'), c = re.compile('[^aeiouAEIOU]')
string.count('e'), # use findall() to get the list of strings
string.count( # that have characters other than a,e,i,o and
'i'),
u.
string.count('o'),
if(len(c.findall(sampleInput))):
string.count('u')]
# Driver code
if __name__ == "__main__":
string = "SEEquoiaL"
print(check(string))