Home > Backend Development > Python Tutorial > 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

青灯夜游
Release: 2023-01-05 16:09:26
Original
102595 people have browsed it

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))
Copy after login

Running result:

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

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template