程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Blue Bridge Cup Python decimal to hexadecimal letter case conversion CSDN creative punch card

編輯:Python

Resource constraints

The time limit :1.0s Memory limit :512.0MB

Problem description

Hexadecimal number is a kind of integer expression that is often used in program design . It has 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F common 16 Symbols , They represent decimal numbers respectively 0 to 15. The hexadecimal counting method is full 16 Into the 1, So decimal numbers 16 In hexadecimal it's 10, And decimal 17 In hexadecimal it's 11, And so on , Decimal 30 In hexadecimal it's 1E.
Give a nonnegative integer , Express it in hexadecimal form .

Input format

The input contains a non negative integer a, Represents the number to convert .0<=a<=2147483647

Output format

The output of this integer is 16 Hexadecimal said

The sample input

30

Sample output

1E

Implementation code

n=input()
k=hex(int(n))
print(k[2:].upper())

matters needing attention

use hex() The hexadecimal number output by the function after conversion is represented by lowercase letters by default
In this case upper() Function to convert upper and lower case letters

m = 'qeddQSD'
m.upper()# All capitals 
m.lower()# All letters lowercase 
m.capitalize()# title case , Other letters are lowercase 
m.title()# Capitalize the first letter of each word , Other lowercase 

At the same time, the first two decimal symbols of the number shall be omitted during output

k = 'ox1e'
print(k[2:])

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved