Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Julia 剪刀石頭布
  2. """
  3. `input(prompt::AbstractString="")`
  4.  
  5. Read a string from STDIN. The trailing newline is stripped.
  6.  
  7. The prompt string, if given, is printed to standard output without a
  8. trailing newline before reading input.
  9. """
  10. function input(prompt::AbstractString="")
  11. print(prompt)
  12. return chomp(readline())
  13. end
  14.  
  15. while true
  16. computer=rand([1:3;])
  17. ans = parse(Int,input("1:剪刀,2:石頭,3:布,輸入1~3: "))
  18.  
  19. if computer == ans
  20. println("平手")
  21. elseif computer < ans
  22. if (computer, ans) != (1, 3)
  23. println("a電腦出 $computer, 你贏了")
  24. else
  25. println("b電腦出 $computer, 你輸了")
  26. end
  27. elseif (computer, ans) != (3, 1)
  28. println("c電腦出 $computer, 你輸了")
  29. else
  30. println("d電腦出 $computer, 你贏了")
  31. end
  32. end
  33.  
  34. # vim:et sw=4 ts=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement