Loading...
More Python Posts
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)
import mysql.connectormydb = mysql.connector.connect(host="localhost",user="yourusername",password="yourpassword")mycursor = mydb.cursor()mycursor.execute("CREATE DATABASE mydatabase")
# importing the modulesimport osimport shutil# getting the current working directorysrc_dir = os.getcwd()# printing current directoryprint(src_dir)# copying the filesshutil.copyfile('test.txt', 'test.txt.copy2') #copy src to dst# printing the list of new filesprint(os.listdir())
filename = "data.txt"with open(filename, "r") as file:file_contents = file.readlines()file_contents = [line.strip() for line in file_contents]print("File contents:")for line in file_contents:print(line)
color2 = (60, 74, 172)color1 = (19, 28, 87)percent = 1.0for 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
import os# Get the current directorycurrent_dir = os.getcwd()# Loop through each file in the current directoryfor filename in os.listdir(current_dir):# Check if the file name starts with a number followed by a period and a spaceif filename[0].isdigit() and filename[1] == '.' and filename[2] == ' ':# Remove the number, period, and space from the file namenew_filename = filename[3:]# Rename the fileos.rename(os.path.join(current_dir, filename), os.path.join(current_dir, new_filename))