• Sep 20, 2025 •cntt.dsc-f4b6
1 like • 2 views
print(123)
• Mar 10, 2021 •Skrome
0 likes • 2 views
color2 = (60, 74, 172) color1 = (19, 28, 87) percent = 1.0 for i in range(101): resultRed = round(color1[0] + percent * (color2[0] - color1[0])) resultGreen = round(color1[1] + percent * (color2[1] - color1[1])) resultBlue = round(color1[2] + percent * (color2[2] - color1[2])) print((resultRed, resultGreen, resultBlue)) percent -= 0.01
• 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)
# 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)
• 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])
• Nov 18, 2022 •AustinLeath
0 likes • 5 views
mydict = {'carl':40, 'alan':2, 'bob':1, 'danny':0} # How to sort a dict by value Python 3> sort = {key:value for key, value in sorted(mydict.items(), key=lambda kv: (kv[1], kv[0]))} print(sort) # How to sort a dict by key Python 3> sort = {key:mydict[key] for key in sorted(mydict.keys())} print(sort)