Computer Science, Python.
Write a program to input a 6 digit number and divide it into three 2 digit numbers.
Answers
The variable num is where your two digit number goes in. num1 and num2 is where the split digits will be stored to.
The second line takes the tens digit of the number. Since dividing in C programming only takes the whole number and disregarding the remainder, this will take the tens digit. Try dividing a two digit number by ten and disregarding the remainder and you’ll see that the answer is the digit itself.
The third line utilizes the modulo operation. This will take the remainder. For example, 17 % 10 = 7. When you divide 17 by 10, you get 1 remainder 7. Since modulo takes the remainder, the answer is 7. Try it for yourself.
The following cσdes have been written using Python.
Source cσde:
n = int(input("Enter a 6 - digit number: "))
if n > 99999:
n1 = n%100
nn1 = n//100
n2 = nn1%100
nn2 = nn1//100
n3 = nn2%100
print("The three 2 - digit numbers are: ")
print(n1)
print(n2)
print(n3)
else:
print("Please enter a 6 - digit number.")
- The if-else clause is used to test for conditions.
- % is used when you want to find the remainder alone.
- // is used when you want to find the quotient alone.