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

Class 10 Coding Showcase Practice Code

The document contains Python programs for various basic functionalities including a simple calculator, number triangle patterns, vowel counting in a sentence, and a diamond pattern. Each program prompts the user for input and performs operations based on that input. The code snippets demonstrate the use of loops and functions to achieve the desired outputs.

Uploaded by

dardaharshit
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)
4 views

Class 10 Coding Showcase Practice Code

The document contains Python programs for various basic functionalities including a simple calculator, number triangle patterns, vowel counting in a sentence, and a diamond pattern. Each program prompts the user for input and performs operations based on that input. The code snippets demonstrate the use of loops and functions to achieve the desired outputs.

Uploaded by

dardaharshit
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/ 3

# Prgram 1 Basic Calculator with User Input

def cal():
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("\nSimple Calculator Results:")
print(f"Addition: {a + b}")
print(f"Subtraction: {a - b}")
print(f"Multiplication: {a * b}")
cal()

# Prgram 2-- Pattern 1: Number Triangle


# Number Triangle Pattern with User-defined Rows
rows = int(input("Enter the number of rows for the
triangle pattern: "))
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=" ")
print()
# Prgram 3 Right-Aligned Number Triangle
# Right-Aligned Number Triangle
for i in range(1, rows + 1):
print(" " * (rows - i) + " ".join(str(j) for j in
range(1, i + 1)))

# Prgram 4--String Manipulation and


Diamond Pattern
# Vowel Count in a User-entered Sentence
def count_vowels():
sentence = input("Enter a sentence: ")
vowels = 'aeiouAEIOU'
count = sum(1 for char in sentence if char in
vowels)
print(f"The sentence '{sentence}' contains
{count} vowels.")
count_vowels()

# Prgram 5 -- Diamond Pattern


# Diamond Pattern with User-defined Rows
rows = int(input("Enter the number of rows for the
diamond pattern: "))
for i in range(rows):
print(" " * (rows - i - 1) + "* " * (i + 1))
for i in range(rows - 1, 0, -1):
print(" " * (rows - i) + "* " * i)

# Prgram 6-- Star Pyramid Pattern


print("\n--- Star Pyramid Pattern ---")
# Star Pyramid Pattern with Nested Loops
rows = int(input("Enter the number of rows for the
pyramid pattern: "))
for i in range(1, rows + 1):
print(" " * (rows - i) + "* " * i)

You might also like