Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # if n is odd, print Weird
- # if n is even and in the inclusive range of 2 to 5,print Not Weird
- # if n is even and in the inclusive range of 6 to 20, print Weird
- # if n is even and greater than 20, print Not Weird
- if __name__ == '__main__':
- n = int(raw_input())
- #if n % 2: #python 里面没有括号,
- # 因为java里面 n%2 这样写不行,一定要n%2 ==0 ,因为n%2返回int类型,而if需要boolean类型。
- # c/c++ 和python里面可以直接这么写, 背后的逻辑,n%2 的返回值类型应该是和if 需要的是一致的。
- # python :
- # if expression: n%2 是一个expression.
- # java :
- # An if-then-else statement is executed by first evaluating the Expression. If the result is of type Boolean, it is subject to unboxing conversion
- if n&1: # python里面位运算: &,与,| ,或,^ 异或。
- print "Weird"
- elif 2<= n <= 5: # python里面这样写是合法的,java和c里面要分开,2 <= n && n <= 5
- print "Not Weird"
- elif 6<=n <= 20:
- print "Weird"
- else:
- print "Not Weird"
Add Comment
Please, Sign In to add comment