In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to solve the three-digit problem in reverse order in python". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to solve the three-digit problem in reverse order in python" can help you solve the problem.
Three digits in reverse order of python
The program reads a positive 3-digit number at a time, and then outputs the digits in reverse order. Note: when the input number contains the ending 0, the output should not have a leading 0. For example, the input is 700 and the output should be 7.
Input format:
Each test is a 3-digit positive integer.
Output format:
Outputs the number in reverse bitwise order.
Enter a sample:
one hundred and twenty three
Sample output:
three hundred and twenty one
Train of thought
Let's talk about two ideas here.
1. Using the method of slicing
Use string slicing methods such as [::-1]
First get the input, then slice the obtained string, convert it to int type and then output it.
A = input () print (int (a [::-1])
two。 The method of using list and subscript to take values
Here, we judge whether the ten digits are zero when the end is 0.
Such as:
123 output in reverse order is 321
120 output in reverse order to 21
100 output in reverse order to 1
X = input () x = list (x) a = int (x [0]) b = int (x [1]) c = int (x [2]) if c = 0: if b = 0: print (a) else: print ("% d% d"% (b, a)) else: print ("% d%d%d"% (c, b, a)) Python three-digit reverse output basic method
Program effect: output a three-digit positive integer an in reverse order.
For example:
There are many ways to solve this problem. Here are a few examples:
1. Using slicing operation a=123b=str (a) print (b [::-1]) 2. Using for cycle a=123b=str (a) c = "" for i in b: c=i+cprint (c) 3. Mathematical method: a123 / 10*10+a//100print 100 + (a0) / / a0 (b) 4. String "index" + "concatenation" operation a=123b=str (a) cymb [2] + b [1] + b [0] print (c) this is the end of the introduction on "how to solve the three-digit problem of reverse order in python". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.