Skip to main content

Nodes and Trees

0 likes • Nov 18, 2022 • 0 views
Python
Loading...

More Python Posts

Finding NULL values within set

0 likes • Oct 7, 2022 • 1 view
Python
x[cat_var].isnull().sum().sort_values(ascending=False)

Convert Decimal to Binary and Hexadecimal

0 likes • May 31, 2023 • 0 views
Python
# Prompt user for a decimal number
decimal = int(input("Enter a decimal number: "))
# Convert decimal to binary
binary = bin(decimal)
# Convert decimal to hexadecimal
hexadecimal = hex(decimal)
# Display the results
print("Binary:", binary)
print("Hexadecimal:", hexadecimal)

Hello World

0 likes • Sep 9, 2023 • 11 views
Python
print("test")

integer to roman numeral

0 likes • Nov 19, 2022 • 0 views
Python
def to_roman_numeral(num):
lookup = [
(1000, 'M'),
(900, 'CM'),
(500, 'D'),
(400, 'CD'),
(100, 'C'),
(90, 'XC'),
(50, 'L'),
(40, 'XL'),
(10, 'X'),
(9, 'IX'),
(5, 'V'),
(4, 'IV'),
(1, 'I'),
]
res = ''
for (n, roman) in lookup:
(d, num) = divmod(num, n)
res += roman * d
return res
to_roman_numeral(3) # 'III'
to_roman_numeral(11) # 'XI'
to_roman_numeral(1998) # 'MCMXCVIII'

Print pyramid pattern

0 likes • Nov 19, 2022 • 0 views
Python
def print_pyramid_pattern(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i+1):
# printing stars
print("* ",end="")
# ending line after each row
print("\r")
print_pyramid_pattern(10)

Lonely Integer

0 likes • Feb 26, 2023 • 0 views
Python
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77
# xor a list of integers to find the lonely integer
res = a[0]
for i in range(1,len(a)):
res = res ^ a[i]