Guest User

Untitled

a guest
Nov 18th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # if n is odd, print Weird
  2. # if n is even and in the inclusive range of 2 to 5,print Not Weird
  3. # if n is even and in the inclusive range of 6 to 20, print Weird
  4. # if n is even and greater than 20, print Not Weird
  5.  
  6.  
  7. if __name__ == '__main__':
  8. n = int(raw_input())
  9. #if n % 2: #python 里面没有括号,
  10. # 因为java里面 n%2 这样写不行,一定要n%2 ==0 ,因为n%2返回int类型,而if需要boolean类型。
  11. # c/c++ 和python里面可以直接这么写, 背后的逻辑,n%2 的返回值类型应该是和if 需要的是一致的。
  12. # python :
  13. # if expression: n%2 是一个expression.
  14. # java :
  15. # 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
  16.  
  17. if n&1: # python里面位运算: &,与,| ,或,^ 异或。
  18. print "Weird"
  19. elif 2<= n <= 5: # python里面这样写是合法的,java和c里面要分开,2 <= n && n <= 5
  20. print "Not Weird"
  21. elif 6<=n <= 20:
  22. print "Weird"
  23. else:
  24. print "Not Weird"
Add Comment
Please, Sign In to add comment