English

Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user-defined function. - Computer Science (Python)

Advertisements
Advertisements

Question

Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user-defined function.

Answer in Brief
Advertisements

Solution

Program:
#defining the function to check the divisibility using the modulus operator
def checkDivisibility(n):
    if n % 7 == 0:
        print(n, "is divisible by 7")
    else:
        print(n, "is not divisible by 7")

#asking the user to provide value for a number
n = int(input("Enter a number to check if it is divisible by 7 : "))

#calling the function
checkDivisibility(n)

OUTPUT:
Enter a number to check if it is divisible by 7 : 7712838152
7712838152 is not divisible by 7
shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Functions - Exercise [Page 172]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 7 Functions
Exercise | Q 1. | Page 172
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×