python中八进制

Syntax to convert octal value to an integer (decimal format),

将八进制值转换为整数(十进制格式)的语法,

    int(oct_value, 8)

Here,

这里,

  • oct_value should contain the valid octal value

    oct_value应该包含有效的八进制值

  • 8 is the base value of the octal number system

    8是八进制数的基值

Note: oct_value must contain only octal digits (0, 1, 2, 3 ,4 ,5 ,6, 7), if it contains other than these digits a "ValueError" will return.

注意oct_value必须仅包含八进制数字(0、1、2、3、4、5、6、7),如果它不包含这些数字,则将返回“ ValueError”

程序将给定的八进制值转换为整数(十进制) (Program to convert given octal value to integer (decimal))

# function to convert given octal Value
# to an integer (decimal number)
def OctToDec(value):
try:
return int(value, 8)
except ValueError:
return "Invalid Octal Value"
# Main code
input1 = "1234567"
input2 = "7001236"
input3 = "1278"
print(input1, "as decimal: ", OctToDec(input1))
print(input2, "as decimal: ", OctToDec(input2))
print(input3, "as decimal: ", OctToDec(input3))

Output

输出量

1234567 as decimal:  342391
7001236 as decimal:  1835678
1278 as decimal:  Invalid Octal Value

Now, we are going to implement the program – that will take input the number as an octal number and printing it in the decimal format.

现在,我们将实现该程序–将输入的数字作为八进制数字并以十进制格式打印。

程序以八进制格式输入数字 (Program to input a number in octal format)

# input number in octal format and
# converting it into decimal format
try:
num = int(input("Input octal value: "), 8)
print("num (decimal format):", num)
print("num (octal format):", oct(num))
except ValueError:
print("Please input only octal value...")

Output

输出量

RUN 1:
Input octal value: 1234567
num (decimal format): 342391
num (octal format): 0o1234567
RUN 2:
Input octal value: 12700546
num (decimal format): 2851174
num (octal format): 0o12700546
RUN 3:
Input octal value: 12807
Please input only octal value...

Recommended posts

推荐的帖子

  • Read input as an integer in Python

    在Python中将输入读取为整数

  • Read input as a float in Python

    在Python中以浮点形式读取输入

  • Parse a string to float in Python (float() function)

    解析要在Python中浮动的字符串(float()函数)

  • How do you read from stdin in Python?

    您如何从Python的stdin中读取信息?

  • Asking the user for integer input in Python | Limit the user to input only integer value

    要求用户在Python中输入整数| 限制用户仅输入整数值

  • Asking the user for input until a valid response in Python

    要求用户输入直到Python中的有效响应

  • Input a number in hexadecimal format in Python

    在Python中以十六进制格式输入数字

  • Input a number in binary format in Python

    在Python中以二进制格式输入数字

  • How to get the hexadecimal value of a float number in python?

    如何在python中获取浮点数的十六进制值?

  • Convert an integer value to the string using str() function in Python

    使用Python中的str()函数将整数值转换为字符串

  • Convert a float value to the string using str() function in Python

    使用Python中的str()函数将浮点值转换为字符串

  • Input and Output Operations with Examples in Python

    使用Python中的示例进行输入和输出操作

  • Taking multiple inputs from the user using split() method in Python

    使用Python中的split()方法从用户获取多个输入

  • Fast input / output for competitive programming in Python

    快速输入/输出,可在Python中进行有竞争力的编程

  • Precision handling in Python

    Python中的精确处理

  • Python print() function with end parameter

    带有结束参数的Python print()函数

翻译自: https://www.includehelp.com/python/input-a-number-in-octal-format.aspx

python中八进制

python中八进制_在Python中以八进制格式输入数字相关推荐

  1. 在Python中以二进制格式输入数字

    Syntax to convert binary value to an integer (decimal format), 将二进制值转换为整数(十进制格式)的语法, int(bin_value, ...

  2. python 时间序列预测_使用Python进行动手时间序列预测

    python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...

  3. python 概率分布模型_使用python的概率模型进行公司估值

    python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...

  4. format函数python的顺序_[转载] Python中format函数用法

    Python中format函数用法 format优点 format是python2.6新增的格式化字符串的方法,相对于老版的%格式方法,它有很多优点. 1.不需要理会数据类型的问题,在%方法中%s只能 ...

  5. python廖雪峰_【Python】python中实现多进程与多线程

    进程与线程 进程(process)就是任务,是计算机系统进行资源分配和调度的基本单位[1].比如,打开一个word文件就是启动了一个word进程. 线程(thread)是进程内的子任务.比如word中 ...

  6. python创建列向量_关于Numpy中的行向量和列向量详解

    关于Numpy中的行向量和列向量详解 行向量 方式1 import numpy as np b=np.array([1,2,3]).reshape((1,-1)) print(b,b.shape) 结 ...

  7. python yield理解_对Python中Yield的理解

    看到下面这段程序的时候,有点不明白这个yield到底是个啥东西,看了网上很多的博客,大致理解了yield的含义,所以记录下来. 要说yield首先要说python中的生成器,那么什么是生成器? 假设有 ...

  8. python selenium 下拉列表_从下拉列表中选择python selenium选项

    我试图使用下面的代码使用selenium(python)从网页上的下拉列表中选择一个选项.在from selenium import webdriver from selenium.webdriver ...

  9. python打印时间_在Python中定义Main函数(第二部分)

    Main函数的最佳实践 既然您已经了解两种执行方式上的差异,那么掌握一些最佳实践方案还是很有用的.它们将适用于编写作为脚本运行的代码或者在另一个模块导入的代码. 如下是四种实践方式: 将大部分代码放入 ...

最新文章

  1. 【Kali渗透全方位实战】使用Nmap进行端口探测-发现脆弱站点
  2. 树莓派与Android客户端进行socket通信
  3. mysql动态分区_MySQL动态创建分区
  4. Go简单的Goroutine示例
  5. mysql error.log 权限_docker-compose 启动mysql 容器时 error.log 无权限访问怎么办?
  6. (转)Virtual PC 2007虚拟网络设置
  7. host文件知识详解
  8. 用python画常密度轮廓线,如何使用Matplotlib在极坐标中绘制具有等高线密度线的散点图?...
  9. SQL语言基础:SQL授权相关知识笔记​
  10. 如何将EDM营销与多渠道推广方式相结合
  11. c语言非法字符有哪些,98行的四则计算器.(支持括号)加入了非法字符的检测
  12. MongoDB 官方C#驱动 封装 DbHelper
  13. 【linux】centos7下muduo库的安装
  14. 马尔可夫性的统计检验(马氏性检验)
  15. 测试工程师面试常见问题总结
  16. 网络运维网管解决方案
  17. Barefoot可编程交换机获ATT订单
  18. 千兆网线水晶头的接法
  19. U盘启动如何进入pe
  20. 隐私计算及密码学学习记录

热门文章

  1. https开头的网址是什么意思_我想打这个面试官,他给我挖坑,问我:URI中的 “//” 有什么用?...
  2. 软件测试用例_软件测试用例设计实战场景法
  3. WebLogic11g 安装配置规范
  4. Linux下的一些简单网络配置命令介绍
  5. Ubuntu主题更换
  6. Problem B: C语言习题 矩阵元素变换
  7. Fusion组件库是如何支持多语言能力的
  8. CSS 字体(font)实例
  9. 关于ASP.NET 中的主题
  10. hadoop 2.5.0安装和配置