Question for tasks that are printed by adding more digits

Asked 2 years ago, Updated 2 years ago, 64 views

print(f"day's digit:",num/1)
print("<<Number extraction operation>>")

num=int (input ("▣four-digit integer =>"))

print ("==== output result ====")

print (f"cloth digits:",num/1000)

num=num%1000

print (f"back digit:",num/100)

num=num%100

print (f"digit:",num/10)

num=num%10

I'm going to do it like the picture above The results of the four-digit integer spacing and the digit output are different, so I'd like your help!

python coding

2022-09-20 16:40

2 Answers

The % operation is to obtain the remainder.

To achieve the desired result, you must perform a quotient operation.

Of course, if you immediately perform a quotient operation for each digit, you can get more than two digits.

Combine the operations of finding the remainder with the operations of finding the quotient


2022-09-20 16:40

print("<<Number extraction operation for name>>")
num = int (input ("four-digit integer => ")))
a = num // 1000
b = (num - a * 1000) // 100
c = (num - a * 1000 - b * 100) // 10
d = (num - a * 1000 - b * 100 - c * 10) // 1
print ("===== output result =====")
print("A Thousand Digits:", a)
print("back digit:", b)
print("10 digits:", c)
print("Position of work:", d)

I don't need five lines of // 1 but I put it in.


2022-09-20 16:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.