Home  >  Article  >  Backend Development  >  How to input a three-digit number in python and output the hundreds, tens and ones digits

How to input a three-digit number in python and output the hundreds, tens and ones digits

青灯夜游
青灯夜游Original
2021-04-16 16:52:31102141browse

Method: 1. Use input() to receive a three-digit number entered from the keyboard and return a string type value; 2. Use int() to convert the accepted value into an integer; 3. Use "number" ", "Number // 10 " and "Number // 100" statements to obtain single digits, tens digits and hundreds digits; 4. Use print() to output.

How to input a three-digit number in python and output the hundreds, tens and ones digits

The operating environment of this tutorial: windows7 system, Python3, Dell G3 computer.

Python inputs a three-digit number and outputs hundreds, tens and ones

#输入number = 123
number = int(input('请输入一个三位数:'))
a = number%10  #个位
b = number//10%10  #十位
c = number//100  #百位
print('%d的百位是:%d'%(number,c)) 
print('%d的十位是:%d'%(number,b)) 
print('%d的个位是:%d'%(number,a))

Running result:

请输入一个三位数:123
123的的百位是:1
123的的十位是:2
123的的个位是:3

[Related recommendations: Python3 video tutorial

The above is the detailed content of How to input a three-digit number in python and output the hundreds, tens and ones digits. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn