Skip to content

Commit

Permalink
Create conv.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fridady0 authored Oct 31, 2024
1 parent 045ec95 commit 7ec8386
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions conv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def convert_number(decimal_number):
# Convert to binary, octal, and hexadecimal
binary_rep = bin(decimal_number)
octal_rep = oct(decimal_number)
hex_rep = hex(decimal_number)

# Display the results
print(f"Decimal: {decimal_number}")
print(f"Binary: {binary_rep}")
print(f"Octal: {octal_rep}")
print(f"Hexadecimal: {hex_rep}")

# Input from the user
try:
decimal_input = int(input("Enter a decimal number: "))
convert_number(decimal_input)
except ValueError:
print("Please enter a valid decimal number.")

0 comments on commit 7ec8386

Please sign in to comment.