Computer Science, asked by luckysurti, 1 month ago

Write a Python Program to Input any 5-digit number and check whether the given number is Divisible by 7 or not​

Answers

Answered by anindyaadhikari13
14

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Python.

def x():

   n=int(input('Enter a five digit number: '))

   if len(str(n))==5:

       if n%7==0:

           print('Number is divisible by 7.')

       else:

           print('Number is not divisible by 7.')

   else:

       print('Number is not a five digit number.')

# Calling x()

x()

\textsf{\large{\underline{Logic}:}}

  1. Accept the number from the user.
  2. Check if the number is a five digit number or not.
  3. If true, check if number is divisible by 7 or not. If true, print "Number is divisible by 7." else print "Number is not divisible by 7."
  4. If false, print "Number is not a five digit number."

\textsf{\large{\underline{Sample I/O}:}}

#1

Enter a five digit number:  7777

Number is not a five digit number.

#2

Enter a five digit number:  12345

Number is not divisible by 7.

#3

Enter a five digit number:  77777

Number is divisible by 7.

Attachments:
Similar questions