Python for inverse ordinal numbers
Method 1.py
num = int(input('Please enter a three-digit integer:')) a = num//100 b = num%100//10 c = num%100%10 print('The inverse of this number is:',(100*c+10*b+a))
num = int(input('Please enter an integer:')) a = 0 while num > 0: a = a*10 + num%10 num = num//10 print('The inverse of this number is:',a)
Method II.py
#Note: this is the method that comes with python a = input('Please enter an integer:') b = int(a[::-1]) print('The inverse of this number is:',b)
Method 3.py
# Note: The inverse ordinal obtained by this method is of type str i = int(input('Please enter an integer:')) s = str(i) l = len(s) a = [] print('The inverse of this number is:',end='') for b in range(l): (s[l-1-b]) for c in a: print(c,end='')
Python list inverse ordinal number solving
What is the inverse ordinal number
In an arrangement, a pair of numbers is called an inverse order if their front and back positions are in the opposite order of magnitude, i.e., the number in front is greater than the number behind. The total number of inverses in an arrangement is called the number of inverses in that arrangement.
That is, in an arrangement, we count the number of numbers after each number that are smaller than itself, and finally add up the numbers to get the inverse order of the list.
ans = 0 a = [1,2,6,3,5,4] for i in range(len(a)):# Circular list for j in range(i):# Determine if the number is followed by a number smaller than itself # if a[j] > a[i]: ans += 1 print(ans)
summarize
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.