Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Julia 剪刀石頭布
- """
- `input(prompt::AbstractString="")`
- Read a string from STDIN. The trailing newline is stripped.
- The prompt string, if given, is printed to standard output without a
- trailing newline before reading input.
- """
- function input(prompt::AbstractString="")
- print(prompt)
- return chomp(readline())
- end
- while true
- computer=rand([1:3;])
- ans = parse(Int,input("1:剪刀,2:石頭,3:布,輸入1~3: "))
- if computer == ans
- println("平手")
- elseif computer < ans
- if (computer, ans) != (1, 3)
- println("a電腦出 $computer, 你贏了")
- else
- println("b電腦出 $computer, 你輸了")
- end
- elseif (computer, ans) != (3, 1)
- println("c電腦出 $computer, 你輸了")
- else
- println("d電腦出 $computer, 你贏了")
- end
- end
- # vim:et sw=4 ts=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement