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 itertoolsimport stringimport timedef guess_password(real):chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuationattempts = 0for password_length in range(1, 9):for guess in itertools.product(chars, repeat=password_length):startTime = time.time()attempts += 1guess = ''.join(guess)if guess == real:return 'password is {}. found in {} guesses.'.format(guess, attempts)loopTime = (time.time() - startTime);print(guess, attempts, loopTime)print("\nIt will take A REALLY LONG TIME to crack a long password. Try this out with a 3 or 4 letter password and see how this program works.\n")val = input("Enter a password you want to crack that is 9 characters or below: ")print(guess_password(val.lower()))

from functools import partialdef curry(fn, *args):return partial(fn, *args)add = lambda x, y: x + yadd10 = curry(add, 10)add10(20) # 30

# 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)

print(“Hello World”)

class Rectangle:passclass Square(Rectangle):passrectangle = Rectangle()square = Square()print(isinstance(rectangle, Rectangle)) # Trueprint(isinstance(square, Rectangle)) # Trueprint(isinstance(square, Square)) # Trueprint(isinstance(rectangle, Square)) # False