• Jul 24, 2024 •AustinLeath
0 likes • 3 views
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])
• Sep 20, 2025 •cntt.dsc-f4b6
1 like • 2 views
print(123)
• May 31, 2023 •CodeCatch
0 likes • 1 view
def generate_pascals_triangle(num_rows): triangle = [] for row in range(num_rows): # Initialize the row with 1 current_row = [1] # Calculate the values for the current row if row > 0: previous_row = triangle[row - 1] for i in range(len(previous_row) - 1): current_row.append(previous_row[i] + previous_row[i + 1]) # Append 1 at the end of the row current_row.append(1) # Add the current row to the triangle triangle.append(current_row) return triangle def display_pascals_triangle(triangle): for row in triangle: for number in row: print(number, end=" ") print() # Prompt the user for the number of rows num_rows = int(input("Enter the number of rows for Pascal's Triangle: ")) # Generate Pascal's Triangle pascals_triangle = generate_pascals_triangle(num_rows) # Display Pascal's Triangle display_pascals_triangle(pascals_triangle)
• Nov 19, 2022 •CodeCatch
# Python code to demonstrate # method to remove i'th character # Naive Method # Initializing String test_str = "CodeCatch" # Printing original string print ("The original string is : " + test_str) # Removing char at pos 3 # using loop new_str = "" for i in range(len(test_str)): if i != 2: new_str = new_str + test_str[i] # Printing string after removal print ("The string after removal of i'th character : " + new_str)
0 likes • 2 views
# Prompt user for base and height base = float(input("Enter the base of the triangle: ")) height = float(input("Enter the height of the triangle: ")) # Calculate the area area = (base * height) / 2 # Display the result print("The area of the triangle is:", area)
• Sep 9, 2023 •AustinLeath
0 likes • 24 views
print("test")