You are on page 1of 3

Converting decimal to binary

def decimal2Binary(dec):
binaryString = ""

while dec > 0:


rem = dec % 2
binaryString = str(rem)+ binaryString

dec = dec // 2
return binaryString

d = int(input("Enter a decimal to convert to binary: "))


print(decimal2Binary(d))

Result:

Converting decimal to hexadecimal


def decimal2Hexa(dec):
hexaString= ""
while dec > 0:
rem = dec % 16
if rem == 10:
hexaString = "A" + hexaString
elif rem == 11:
hexaString = "B" + hexaString
elif rem == 12:
hexaString = "C" + hexaString
elif rem == 13:
hexaString = "D" + hexaString
elif rem == 14:
hexaString = "E" + hexaString
elif rem == 15:
hexaString = "F" + hexaString
else :
hexaString= str(rem) + hexaString

dec = dec//16

return hexaString

d = int(input("Enter a decimal to convert to hexadecimal: "))


print(decimal2Hexa(d))

Result:
Translator
from translate import Translator
language_code = "nl"
translator = Translator(language_code)
translation = translator.translate("Hello my name is daniel")
print(translation)

Result:

How old are you?


year = int(input("What year were you born?"))

if year < 2017:


print("You are this old: ", 2017 - year)
elif year == 2017:
print("Happy birthday you are brand new!")
else:
print("WOW! you are from the future!")

Result:

E = mc
import math
def einstein( m, c):
E = m * c ** 2
return E

m = int(input("Enter the mass: "))


c = int(input("Enter the speed: "))

itsAllRelative = einstein(m, c)
print("The amount of energy is: ", itsAllRelative)

Result:
Guess the age
guess = 0
age = 16
while guess != age:
guess = int(input("How old am I?"))
if guess < age:
print("Too young!")
elif guess > age:
print("Too old!")
else:
guess == age
print("You are correct!!")

Result:

You might also like