Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decimal_to_binary(decimal):
- try:
- decimal = int(decimal)
- except ValueError:
- print("Invalid input. Please enter a valid integer.")
- return
- if decimal < 0:
- print("Decimal number cannot be negative.")
- return
- binary = bin(decimal)[2:] # Remove the '0b' prefix from the binary representation
- return binary
- decimal_number = input("Enter a decimal number: ")
- binary_representation = decimal_to_binary(decimal_number)
- if binary_representation:
- print(f"Binary representation: {binary_representation}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement