Loading...
More Python Posts
import pandas as pdx = pd.read_excel(FILE_NAME)print(x)
def generate_pascals_triangle(num_rows):triangle = []for row in range(num_rows):# Initialize the row with 1current_row = [1]# Calculate the values for the current rowif 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 rowcurrent_row.append(1)# Add the current row to the triangletriangle.append(current_row)return triangledef display_pascals_triangle(triangle):for row in triangle:for number in row:print(number, end=" ")print()# Prompt the user for the number of rowsnum_rows = int(input("Enter the number of rows for Pascal's Triangle: "))# Generate Pascal's Trianglepascals_triangle = generate_pascals_triangle(num_rows)# Display Pascal's Triangledisplay_pascals_triangle(pascals_triangle)
def byte_size(s):return len(s.encode('utf-8'))byte_size('😀') # 4byte_size('Hello World') # 11
bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)
def when(predicate, when_true):return lambda x: when_true(x) if predicate(x) else xdouble_even_numbers = when(lambda x: x % 2 == 0, lambda x : x * 2)print(double_even_numbers(2)) # 4print(double_even_numbers(1)) # 1
# Input for row and columnR = int(input())C = int(input())# Using list comprehension for inputmatrix = [[int(input()) for x in range (C)] for y in range(R)]