julia(6)-循环与猜数字
生活随笔
收集整理的這篇文章主要介紹了
julia(6)-循环与猜数字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
julia> include("G://learn//1.jl")
電腦已經產生一個1~200之內的數字
┌ Warning: Assignment to `player_num` in soft scope is ambiguous because a global variable by the same name exists: `player_num` will be treated as a new local. Disambiguate by using `local player_num` to suppress this warning or `global player_num` to assign to the existing global variable.
└ @ G:\learn\1.jl:7
請輸入您猜的數字:129
數字小了
請輸入您猜的數字:60
數字小了
請輸入您猜的數字:190
數字大了
請輸入您猜的數字:170
數字小了
請輸入您猜的數字:180
數字大了
請輸入您猜的數字:75
數字小了
請輸入您猜的數字:17
數字小了
請輸入您猜的數字:175
數字大了
請輸入您猜的數字:12
數字小了
請輸入您猜的數字:172
數字小了
請輸入您猜的數字:173
數字小了
請輸入您猜的數字:174
猜對了,恭喜
#code:https://blog.csdn.net/AI_LX
#轉載請注意代碼來源
guess_num=rand(1:200,1)[1] #產生一個1-200之間的隨機數
player_num=-100
println("電腦已經產生一個1~200之內的數字")
while player_num!=guess_numprint("請輸入您猜的數字:")input_num=readline()player_num=parse(Int,input_num)if player_num>guess_numprintln("數字大了")elseif player_num<guess_numprintln("數字小了")elseprintln("猜對了,恭喜")breakend
end
總結
以上是生活随笔為你收集整理的julia(6)-循环与猜数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nacos初探--作为配置中心
- 下一篇: 项目构建之springboot集成lom