• Jun 1, 2023 •CodeCatch
0 likes • 1 view
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)
0 likes • 3 views
bytes_data = b'Hello, World!' string_data = bytes_data.decode('utf-8') print("String:", string_data)
• Mar 10, 2021 •Skrome
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
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
def check_prop(fn, prop): return lambda obj: fn(obj[prop]) check_age = check_prop(lambda x: x >= 18, 'age') user = {'name': 'Mark', 'age': 18} check_age(user) # True
• May 31, 2023 •CodeCatch
# 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)
import math def factorial(n): print(math.factorial(n)) return (math.factorial(n)) factorial(5) factorial(10) factorial(15)