goinaction / code

Source Code for Go In Action examples
4.14k stars 2.38k forks source link

Banane #108

Open yoshiki98 opened 1 year ago

reddyyoge commented 1 year ago

Check integer for conditions.



Please submit your assignment here Solve the below given assignment for the respective class to reach certificate eligibility Given an integer M perform the following conditional actions: - If M is multiple of 3 and 5 then print "Good Number" (without quotes). - If M is only multiple of 3 and not of 5 then print "Bad Number" (without quotes). - If M is only multiple of 5 and not of 3 then print "Poor Number" (without quotes). - If M doesn't satisfy any of the above conditions then print "-1" (without quotes)

Here's the solution to the given problem:

pythonCopy code

Taking input from user M = int(input()) # Checking the conditions and printing the result accordingly if M % 3 == 0 and M % 5 == 0: print("Good Number") elif M % 3 == 0: print("Bad Number") elif M % 5 == 0: print("Poor Number") else: print("-1")

Explanation:

We first take the input integer from the user using the input() function and convert it to an integer using the int() function.

We then check the given conditions using the modulo operator %. If M is divisible by both 3 and 5, we print "Good Number". If M is only divisible by 3, we print "Bad Number". If M is only divisible by 5, we print "Poor Number". If M doesn't satisfy any of these conditions, we print "-1".

Example:

makefileCopy code

Input: 15 Output: Good Number

makefileCopy code

Input: 9 Output: Bad Number

makefileCopy code

Input: 20 Output: Poor Number

makefileCopy code

Input: 7 Output: -1