如何使用 python 将整数转换为十六进制?
How do I make an integer to hex converter with python?
我目前正在尝试在 python 中制作一个整数到十六进制的转换器。我试过 运行 我的代码,但是它
一直给我这个错误:
Traceback (most recent call last):
File "C:\Users\Saumya\Documents\Coding\Python\hex.py", line 2, in <module>
hex(num1)
TypeError: 'str' object cannot be interpreted as an integer
这是我的代码:
num1 = input("Enter a Number to Convert to Hex:")
hex(num1)
请尽快给我答复
input
returns 一个字符串。您必须将其转换为整数:
hex(int(num1))
我目前正在尝试在 python 中制作一个整数到十六进制的转换器。我试过 运行 我的代码,但是它 一直给我这个错误:
Traceback (most recent call last):
File "C:\Users\Saumya\Documents\Coding\Python\hex.py", line 2, in <module>
hex(num1)
TypeError: 'str' object cannot be interpreted as an integer
这是我的代码:
num1 = input("Enter a Number to Convert to Hex:")
hex(num1)
请尽快给我答复
input
returns 一个字符串。您必须将其转换为整数:
hex(int(num1))