Hello everyone 👋, in this article📃 I'll be discussing about how I m learning JuliaLang by building mini projects.
Lets start building Rock Paper Scissors game using JuliaLang.
But first we definitely need an IDE or TextEditor for running JuliaLang code.
We can use VSCode with required extension for running JuliaLang code but since I have just started with JuliaLang so I used repl.it here for coding and exploring JuliaLang(its an awesome online IDE try it).
Motivation behind getting started with Learning JuliaLang:
- Best part about JuliaLang is that it is easy to learn just like Python.
- The execution speed of JuliaLang is similar to C/C++. That means it's fast.
- And it is widely used for Data Science , Machine Learning , Deep Learning and even Web Development(And more lot stuff).
- And JuliaLang Community is wide & inclusive,if you stuck somewhere while creating any project using JuliaLang. There are many amazing folks to help you. And if are mathematics, bioinformatics or something related to Statistics and Maths or even you are just a Tech Enthusiast join JuliaLang slack channel. You will find many awesome peers who are enthusiast from of the above fields.
- Around 200+ JuliaLang packages are present to make your development work more easy.
Complete Code :
# learning julialang basics by creating classical stone paper scissors game function play_game() moves = ["rock","paper","scissor"] computer_move = moves[rand(1:3)] human_move = Base.prompt("Please enter stone, paper, or scissor") print("Rock...") sleep(1.0) print("Paper...") sleep(1.0) print("Scissors...") sleep(1.0) print("Shoot!\n") if computer_move == human_move print("You tied, please try again") elseif computer_move == "rock" && human_move == "scissor" print("You lose, the computer won with rock, please try again") elseif computer_move == "paper" && human_move == "rock" print("You lose, the computer won with paper, please try again") elseif computer_move == "scissor" && human_move == "paper" print("You lose, the computer won with scissor, please try again") else print("You won, the computer lost with $computer_move, nice work!") end end
My Learnings from this mini project build:
1) Learned how to write comment in JuliaLang.
# This is how we write JuliaLang comments # hashtag followed with text you wanted to commented
2) Learned how to print text.
print("Your text here inside double quotes")
3) Learned how to create function(without parameters)
function fun_name() . your code here . end
Whenever you create function its necessary to tell compiler where to stop by using end keyword in JuliaLang.
4) Learned how to use conditional loop (if-elseif-else loop).
function test(x, y) if x < y println("x is less than y") elseif x > y println("x is greater than y") else println("x is equal to y") end end
Whenever we use if-else or if-elseif-else conditional loop after the else condition statement we should use end keyword to tell compiler where does the conditional loops ends.
5) Learned about few inbuilt function.
- sleep() : Its an inbuilt method of JuliaLang which comes under Base class and we don't need to import package for it. It basically stops execution of code for specified time. The minimum sleep time is 1 milliseconds.
- rand() : It picks random element from array or list of elements. And similar to sleep method its an inbuilt method which comes under Base class.
Here we randomly selected 1 element from 3 elements inside the collection.
Github Repository for mini Projects using JuliaLang
(Thanks @logankilpatrick for providing awesome mini projects repository)
logankilpatrick / Julia-Projects-for-Beginners
Julia Projects for Beginners — Easy Ideas to Get Started Coding in Julia
Top comments (3)
I love this! Glad it is helping you :)
I'm currently learning JuliaLang I might have missed something.
Feedback is always welcomed :)