0
If-else conditional statement problem
Task Given an integer, , perform the following conditional actions: If is odd, print Weird If is even and in the inclusive range of to , print Not Weird If is even and in the inclusive range of to , print Weird If is even and greater than , print Not Weird Input Format A single line containing a positive integer, . Constraints Output Format Print Weird if the number is weird. Otherwise, print Not Weird. This is what i have written so far and i am kind of stuck #!/bin/python import math import os import random import re import sys if __name__ == '__main__': n = int(raw_input().strip()) if n <=
4 Respuestas
+ 1
n,c10,c11 = input().split(" ")
c10 = int(c10)
c11 = int(c11)
n = int(n)
if n%2 == 0 and n in range(c10,c11+1):
print("Weird")
elif n%2 == 0 and n not in range(c10,c11+1):
print("Not Weird")
# elif for n as even with an other range etc.
else:
print("Weird")
0
You can use the '%' (modulo) operator. Then for the 'greater than' and such you can use simple 'if value >... :"
By the way I do think you can just put n = int(input()) instead of raw_input and strip.
0
Thank your Arthur Le Floch , I took your advice and managed to get it right.
n = int(raw_input().strip())
check = {True: "Not Weird", False: "Weird"}
if n <= n:
print (check[
n%2 == 0 and (
n in range (2,5) or
n > 20)
])
0
Cool 😎, have a nice day !