From 127bf6b68296ce9a79dbd2e375ad3733385c1c03 Mon Sep 17 00:00:00 2001 From: cuichao Date: Tue, 3 Oct 2017 16:10:47 +0800 Subject: [PATCH] simplify dec_to_hex.py --- dec_to_hex.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/dec_to_hex.py b/dec_to_hex.py index 22df25a3d87..ce358712db7 100644 --- a/dec_to_hex.py +++ b/dec_to_hex.py @@ -1,12 +1,2 @@ -mydict={ - '0':'0','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'A','11':'B', - '12':'C','13':'D','14':'E','15':'F' - } -dec_num=input('Enter the decimal number\n'); -dec_num=int(dec_num) -value="" -while dec_num>0: - value+=mydict[str(dec_num%16)] - dec_num=dec_num//16 -hex_value=value[::-1] -print(hex_value) +dec_num=input('Enter the decimal number\n') +print(hex(int(dec_num)))