Given an integer value, if it is divisible by 3 print “HI”, if it is divisible by 5 print “HELLO”. If it is divisible by both print “HIHELLO”, else print "NONE"Input Format:Enter an integer as a inputOutput Format:Follow the format as sample output - "HI"or "HELLO" or "HIHELLO" or "NONE"Constraints:1 <= INPUT <= 10^15Sample Input 1:55Sample Output 1:HELLOSample Input 2:12Sample Output 2:HI
Question
Given an integer value, if it is divisible by 3 print “HI”, if it is divisible by 5 print “HELLO”. If it is divisible by both print “HIHELLO”, else print "NONE"Input Format:Enter an integer as a inputOutput Format:Follow the format as sample output - "HI"or "HELLO" or "HIHELLO" or "NONE"Constraints:1 <= INPUT <= 10^15Sample Input 1:55Sample Output 1:HELLOSample Input 2:12Sample Output 2:HI
Solution
To solve this problem, we need to check if the given integer is divisible by 3, 5, or both. Here are the steps to follow:
- Read the integer input from the user.
- Check if the input is divisible by 3 using the modulo operator (%). If the remainder is 0, it means the input is divisible by 3.
- Check if the input is divisible by 5 using the modulo operator (%). If the remainder is 0, it means the input is divisible by 5.
- Based on the results of the previous two steps, determine the appropriate output:
- If the input is divisible by both 3 and 5, print "HIHELLO".
- If the input is divisible by 3 only, print "HI".
- If the input is divisible by 5 only, print "HELLO".
- If none of the above conditions are met, print "NONE".
Here is the code implementation in Python:
# Step 1: Read the integer input
num = int(input("Enter an integer: "))
# Step 2: Check if divisible by 3
if num % 3 == 0:
# Step 3: Check if divisible by 5
if num % 5 == 0:
# Step 4: Divisible by both 3 and 5
print("HIHELLO")
else:
# Step 4: Divisible by 3 only
print("HI")
elif num % 5 == 0:
# Step 4: Divisible by 5 only
print("HELLO")
else:
# Step 4: Not divisible by 3 or 5
print("NONE")
Sample Input 1: 55 Sample Output 1: HELLO
Sample Input 2: 12 Sample Output 2: HI
Similar Questions
Given an integer value, check the given input is divisible by 3. If it is divisible print the message "The number is divisible by 3".if it is not divisible print the message "The number is not divisible by 3 and gives a remainder _".Input Format:Enter an integer as a inputOutput Format:Follow the format as sample outputConstraints:1 <= INPUT <= 10^15Sample Input 1:54653Sample Output 1:The number is not divisible by 3 and gives a remainder 2Sample Input 2:25Sample Output 2:The number is not divisible by 3 and gives a remainder 1
Write a program to accept an integer range and print the sum of number that are divisible by either 3 or 5Input Format:An integer range is given inputOutput Format:Print the calculated sum.Constraints:1 <= N <= 10^16 Sample Input 1:10Sample Output 1:33Sample Input 2:30Sample Output 2:225
Given a positive integer denoting , do the following:If , print the lowercase English word corresponding to the number (e.g., one for , two for , etc.).If , print Greater than 9.Input FormatThe first line contains a single integer, .ConstraintsOutput FormatIf , then print the lowercase English word corresponding to the number (e.g., one for , two for , etc.); otherwise, print Greater than 9 instead.Sample Input5Sample OutputfiveSample Input #018Sample Output #01eightSample Input #0244Sample Output #02Greater than 9
Given an integer input , whether the given input is "Positive" or "Negative" or "Zero" and print the corresponding messageInput Format:Enter an integer as a input Output Format: Print the output as "Negative" or "Positive" or "Zero"Constraints:1 <= INPUT <= 10^15Sample Input 1:-98Sample Output 1:NEGATIVESample Input 2:0Sample Output 2:ZERO
Given 2 integer input check whether the 2 input are "Equal" or "Not Equal" and print the corresponding message.Input Format:Accept two integers as inputOutput Format:Print the output as "Equal" or "Not Equal"Constraints:1 <= INPUT <= 10^15
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.