Loading...
More Python Posts
def key_of_min(d):return min(d, key = d.get)key_of_min({'a':4, 'b':0, 'c':13}) # b
# Prompt user for base and heightbase = float(input("Enter the base of the triangle: "))height = float(input("Enter the height of the triangle: "))# Calculate the areaarea = (base * height) / 2# Display the resultprint("The area of the triangle is:", area)
def generate_floyds_triangle(num_rows):triangle = []number = 1for row in range(num_rows):current_row = []for _ in range(row + 1):current_row.append(number)number += 1triangle.append(current_row)return triangledef display_floyds_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 Floyd's Triangle: "))# Generate Floyd's Trianglefloyds_triangle = generate_floyds_triangle(num_rows)# Display Floyd's Triangledisplay_floyds_triangle(floyds_triangle)
from math import pidef rads_to_degrees(rad):return (rad * 180.0) / pirads_to_degrees(pi / 2) # 90.0
# Python Program to calculate the square rootnum = float(input('Enter a number: '))num_sqrt = num ** 0.5print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
from colorama import init, Fore# Initialize coloramainit()print(Fore.RED + "This text is in red color.")print(Fore.GREEN + "This text is in green color.")print(Fore.BLUE + "This text is in blue color.")# Reset coloramaprint(Fore.RESET + "This text is back to the default color.")