Given an integer, , perform the following conditional actions:If is odd, print WeirdIf is even and in the inclusive range of to , print Not WeirdIf is even and in the inclusive range of to , print WeirdIf is even and greater than , print Not WeirdInput Format
Question
Given an integer, , perform the following conditional actions:If is odd, print WeirdIf is even and in the inclusive range of to , print Not WeirdIf is even and in the inclusive range of to , print WeirdIf is even and greater than , print Not WeirdInput Format
Solution
Sure, here is a Python solution for the problem:
n = int(input().strip())
if n % 2 == 1:
print('Weird')
elif n % 2 == 0 and 2 <= n <= 5:
print('Not Weird')
elif n % 2 == 0 and 6 <= n <= 20:
print('Weird')
elif n % 2 == 0 and n > 20:
print('Not Weird')
Here is a step by step explanation:
-
n = int(input().strip()): This line is used to take an integer input from the user. Thestrip()function is used to remove any leading or trailing white spaces. -
if n % 2 == 1:: This line checks if the number is odd. If a number is divided by 2 and the remainder is 1, then the number is odd. If the number is odd, it prints 'Weird'. -
elif n % 2 == 0 and 2 <= n <= 5:: This line checks if the number is even and in the inclusive range of 2 to 5. If the condition is true, it prints 'Not Weird'. -
elif n % 2 == 0 and 6 <= n <= 20:: This line checks if the number is even and in the inclusive range of 6 to 20. If the condition is true, it prints 'Weird'. -
elif n % 2 == 0 and n > 20:: This line checks if the number is even and greater than 20. If the condition is true, it prints 'Not Weird'.
Similar Questions
TaskGiven an integer, , perform the following conditional actions:If is odd, print WeirdIf is even and in the inclusive range of to , print Not WeirdIf is even and in the inclusive range of to , print WeirdIf is even and greater than , print Not WeirdInput FormatA single line containing a positive integer, .ConstraintsOutput FormatPrint Weird if the number is weird. Otherwise, print Not Weird.Sample Input 03Sample Output 0WeirdExplanation 0 is odd and odd numbers are weird, so print Weird.Sample Input 124Sample Output 1Not WeirdExplanation 1 and is even, so it is not weird.
What will be the output of the following code?x = -10if x > 0: if x % 2 == 0: print("Positive even") else: print("Positive odd")else: if x % 2 == 0: print("Negative even") else: print("Negative odd")Answer areaPositive evenPositive oddNegative evenNegative odd
Write a program to print only the even numbers till given NInput FormatA single integer 'N'Output FormatDisplay all the even numbers between 0 and NSample Input10Sample Output0 2 4 6 8 10
Write a program to print the odd values in the given rangeInput FormatTwo space separated integers - 'start' and 'end'Output FormatDisplay all the odd numbers between 'start' and 'end'Sample Input10 20Sample Output11 13 15 17 19
Mandy is a software engineer working on a program to analyze two integers based on specific conditions using a logical operator. She needs to determine if both integers are odd or if at least one of them is divisible by 7.Depending on the result, she wants to print different messages. If the condition is met, the program should identify and print the number that is first divisible by 7 or indicate that both numbers are odd.If the condition is not met, the program should print a message indicating the condition was not met along with the input numbers.Input format :The first line of input consists of an integer representing the first input number.The second line consists of an integer representing the second input number.
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.