Python Exercise: Decimal turn hex (selected from Blue Bridge Cup)

Topics requirements:

Time limit: 1.0s Memory Limit: 512.0MB

Problem Description

Hexadecimal number in program design often use to represent a way of integers. It has
0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F total of 16 symbols each represent 0 to 15 decimal.
The method of counting is full hexadecimal 16 into one, the decimal number 16 is 10 in hexadecimal, decimal and
17 is 11 in hexadecimal, and so on, into sixteen decimal 30 system is 1E.
It is given a non-negative integer, which represents the hexadecimal form.

Input format
  input comprises a non-negative integer a, represents a number to be converted. 0 <= a <= 2147483647
output format
  outputs the hexadecimal representation of an integer
sample input
30
Sample Output
1E

Figure Code:

2

code show as below:
'''
时间限制:1.0s   内存限制:512.0MB

问题描述

十六进制数是在程序设计时经常要使用到的一种整数的表示方式。它有
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F共16个符号,分别表示十进制数的0至15。
十六进制的计数方法是满16进1,所以十进制数16在十六进制中是10,而十进制
的17在十六进制中是11,以此类推,十进制的30在十六进制中是1E。
给出一个非负整数,将它表示成十六进制的形式。

输入格式
  输入包含一个非负整数a,表示要转换的数。0<=a<=2147483647
输出格式
  输出这个整数的16进制表示
样例输入
30
样例输出
1E

'''
def main():
    num=input()
    print( '{:X}'.format(int(num)))
main()

running result:

1
Here Insert Picture Description

Published 17 original articles · won praise 2 · Views 447

Guess you like

Origin blog.csdn.net/qq_45894553/article/details/104515728