Accept a number from user and check whether it is multiple of 7 for python
Answers
Answered by
5
Solution:
The given code is written in Python 3.
n=int(input("Enter a number: "))
if n%7==0:
print(n,"is a multiple of 7.")
else:
print(n,"is not a multiple of 7.")
Logic:
- Using % operator, find the remainder when the number is divided by 7.
- Check if the remainder is 0 or not. If it is 0, number is a multiple of 7 else not.
See the attachment for output.
•••♪
Attachments:
Answered by
10
Answer:
n=(int)(input("Enter a number:"))
if n%7==0:
print("Multiple of 7")
else:
print("Not multiple of 7")
Shorter Way:-
n=(int)(input("Enter a number:"))
print("Multiple of 7" if n%7==0 else "Not Multiple of 7")
•Required output Attached
Attachments:
Similar questions