Computer Science, asked by ThisUsernamesTooLong, 2 months ago

Computer Science, Python.

Write a program to input a 6 digit number and divide it into three 2 digit numbers.


studentsainik163: hii

Answers

Answered by Itznunurbusiness
94

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.

Attachments:

sainiinswag: Great
Anonymous: keep up the good work :D
sainiinswag: Perfect
swayamprava12: Great ans my bestie mysa, really good job!!!!!!!
Answered by Equestriadash
192

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.

BrainlyProgrammer: Gr8 Answer!!
IdyllicAurora: @anindyaadhikari, output of a program changes with question. According to the question, its correct and appropriate. The case of 7 digit changes.
anindyaadhikari13: For that, an error message should be displayed.
anindyaadhikari13: as the question says only 6 digit numbers.
BrainlyProgrammer: It's already displayed...check the last line... "Please enter 6 digit number"
BrainlyProgrammer: *line line of the program
anindyaadhikari13: @swetank232894, again you are missing your points. See if n>99999 is false, then only it will display the message - "Please enter a 6 digit number". If the number has 7 digits, then n > 99999 is true as always.
BrainlyProgrammer: @anindyaadhikari... now understood the Question... so it should be n<999999
anindyaadhikari13: yes. or check if len(str(n)) ==6:...
BrainlyProgrammer: that is also correct
Similar questions