BASIC PYTHON PROGRAMS
HOW TO CONVERT DECIMAL TO HEXADECIMAL USING WHILE LOOP, TO REMOVE IMAGE BACKGROUND & TO FIND FACTORIAL OF A NUMBER USING FUNCTIONS USING PYTHON
Mar 4, 2023
#1
✅PYTHON PROGRAM TO CONVERT DECIMAL TO HEXADECIMAL USING WHILE LOOP
conversion_table = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
decimal = int(input("Enter a number:"))
hexadecimal = ''
while(decimal>0):
remainder=decimal%16
hexadecimal=conversion_table[remainder]+hexadecimal
decimal=decimal//16
print("Hexadecimal:",hexadecimal)
#2
✅HOW TO REMOVE IMAGE BACKGROUND USING PYTHON LIBRARY -REMBG?
from rembg import remove
from PIL import Image
import easygui as eg
input_path = eg.fileopenbox(title=’Select image file’)
output_path = eg.filesavebox(title=’Save file to..’)
input = Image.open(input_path)
output = remove(input)
output.save(output_path)
#3
✅WRITE A PYTHON PROGRAM TO FIND FACTORIAL OF A GIVEN NUMBER USING FUNCTIONS
Code:
def fact(n):
return 1 if (n==1 or n==0)else n*fact(n-1)
num=5
print("Factorial of ",num,"is")
fact(num)
An article✍️ by Jivitesh P