I science journey a few years again, and I noticed that a lot of the experiences I gained tended to revolve round knowledge evaluation and theoretical coding.
Wanting again, one of many advantages I obtained from being a pc science main was creating a core understanding of varied programming languages.
Though the draw back is that you’ve got all these theories, however little to no apply.
With that in thoughts, I challenged myself to construct one thing utilizing one of many high programming languages in knowledge science: R.
And sure, I do know what you may be pondering: why R, and never Python?
Effectively, follow me for a minute.
Based on a StrataScratch article, practically 20,000 knowledge professionals have been surveyed, and 31% reported utilizing R day by day.
To me, that 31% is a large slice of the pie, and it obtained me pondering.
If R is highly effective sufficient to crunch hundreds of thousands of rows of information, why dont I additionally use it to apply the basics of programming in relation to knowledge science?
Typically, one of the best ways to develop as an information scientist might not be by leaping straight into machine studying libraries or analyzing massive datasets. It may additionally come from embracing fixed studying and steadily increasing your expertise.
That’s what impressed me to create this challenge, a command-line quiz software in R, proper contained in the terminal.
It’s easy, but it surely teaches the identical expertise you’ll want when constructing extra advanced knowledge pipelines, equivalent to management movement, enter dealing with, and modular capabilities.
On this article, I’ll stroll you thru the method step-by-step, sharing not solely the code but in addition the teachings I picked up alongside the best way.
Dealing with Person Enter
I obtained a little bit emotional right here as a result of this took me again to the primary time I used readline() in R. Seeing this system “wait” for me to kind one thing felt like I used to be having a dialog with my code.
Okay, extra coding, much less nostalgia.
Like most initiatives, I began small, starting with only one query and one reply test.
# First experiment: single query with fundamental enter dealing with
# Bug observe: with out tolower(), "Abuja" vs "abuja" triggered a mismatch
reply <- readline(immediate = "What's the capital of Nigeria? ")
if (tolower(trimws(reply)) == "abuja") {
cat("✅ Right!n")
} else {
cat("❌ Incorrect. The right reply is Abuja.n")
}
This snippet seems to be easy, but it surely introduces two essential concepts:
readline()permits interactive enter within the console.tolower()+trimws()helps normalize responses (avoiding mismatches attributable to case or further areas).
After I first tried this, I typed “Abuja ” with a trailing area, and it marked me improper. With that, I noticed that cleansing enter is simply as essential as amassing it.
Constructing Logic with Management Stream and Features
Initially, I stacked all the pieces inside a single block of if statements, but it surely shortly grew to become messy.
Not my best name, to be trustworthy.
It shortly jogged my memory of structured programming, the place breaking issues into capabilities usually makes the code cleaner and simpler to learn.
# Turned the enter logic right into a reusable operate
# Small bug repair: added trimws() to take away stray areas in solutions
ask_question <- operate(q, a) {
response <- readline(immediate = paste0(q, "nYour reply: "))
if (tolower(trimws(response)) == tolower(a)) {
cat("✅ Right!n")
return(1)
} else {
cat("❌ Incorrect. The right reply is:", a, "n")
return(0)
}
}
# Fast take a look at
ask_question("What's the capital of Nigeria?", "Abuja")
What felt most fulfilling about utilizing capabilities wasn’t simply the cleaner code, however the realization that I used to be lastly training and sharpening my programming expertise.
Information science is sort of like studying a TikTok dance; you solely actually get it when you begin training the strikes your self.
Making a Query Financial institution
To scale the quiz, I wanted a option to retailer a number of questions, as a substitute of simply hardcoding separately. I imply, you may try this, but it surely’s not likely environment friendly.
Now that’s the fantastic thing about R’s checklist construction; it was versatile sufficient to carry each the questions and their solutions, which made it an ideal match for what I used to be constructing.
# Query financial institution: preserving it easy with a listing of lists
# Be aware: began with simply 2 questions earlier than scaling up
quiz_questions <- checklist(
checklist(query = "What's the capital of Nigeria?", reply = "Abuja"),
checklist(query = "Which package deal is usually used for knowledge visualization in R?", reply = "ggplot2")
)
# Later I added extra, however this small set was sufficient to check the loop first.
In my quest to hunt suggestions, I shared this with a good friend who advised including classes (like “Geography” or “R Programming”), which may really be a superb enchancment for later.
Operating the Quiz (Looping By way of Questions)
Now comes the enjoyable half: looping by way of the query financial institution, asking every query, and preserving observe of the rating. This loop is the engine that drives your entire software.
To make this clearer, right here’s a easy flowchart as an instance what I’m saying:

With this construction in thoughts, right here’s the way it seems to be in code:
# Operating by way of the quiz with a rating counter
# (I began with a for loop earlier than wrapping this into run_quiz())
rating <- 0
for (q in quiz_questions) {
rating <- rating + ask_question(q$query, q$reply)
}
cat("📊 Your rating is:", rating, "out of", size(quiz_questions), "n")
Ultimate Touches
To shine issues up, I wrapped the logic right into a run_quiz() operate, making this system reusable and straightforward to know.
# Wrapped all the pieces in a single operate for neatness
# This model prints a welcome message and complete rating
run_quiz <- operate(questions) {
rating <- 0
complete <- size(questions)
cat("👋 Welcome to the R Quiz Sport!n")
cat("You can be requested", complete, "questions. Good luck!nn")
for (q in questions) {
rating <- rating + ask_question(q$query, q$reply)
}
cat("🎉 Ultimate rating:", rating, "out of", complete, "n")
}
# Uncomment to check
# run_quiz(quiz_questions)
At this level, the app felt full. It welcomed the participant, requested a collection of questions, and displayed the ultimate rating with a celebratory message.
Neat.
Pattern Run
Right here’s what it regarded like after I performed it within the R console:
👋 Welcome to the R Quiz Sport!
You can be requested 2 questions. Good luck!
What's the capital of Nigeria?
Your reply: Abuja
✅ Right!
Which package deal is usually used for knowledge visualization in R?
Your reply: ggplot
❌ Incorrect. The right reply is: ggplot2
🎉 Ultimate rating: 1 out of two
Conclusion and Takeaways
Wanting again, this small challenge taught me classes that instantly apply to bigger knowledge science workflows. A command-line quiz sport in R would possibly sound trivial, however belief me, it’s a highly effective train.
In case you’re studying R, I like to recommend attempting your individual model. Add extra questions, and shuffle them. To push your self extra, you may even time-limit responses.
Programming isn’t about reaching a end line; it’s about staying on the educational curve. Small initiatives like this hold you shifting ahead— one operate, one loop, one problem at a time.





