Python Solutions
Python Solutions
Question 24d
Shape Output:
**
* *
* *
* *
**
Solution:
n = 4 # number of rows
# Upper half
x=1
while x < 2 * i:
if x == 1 or x == 2 * i - 1:
print('*', end='')
else:
x += 1
print()
# Lower half
while x < 2 * i:
if x == 1 or x == 2 * i - 1:
print('*', end='')
else:
x += 1
print()
Question 25
return x + y
return x - y
return x * y
if y == 0:
return x / y
print("Select operation:")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
if choice == '1':
else:
print("Invalid Input")
Question 26
def count_vowels_and_consonants(string):
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0
for char in string:
if char in vowels:
vowel_count += 1
else:
consonant_count += 1