• About
  • Advertise
  • Privacy & Policy
  • Contact
Sunday, January 11, 2026
  • Login
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World
    Hillary Clinton in white pantsuit for Trump inauguration

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel
    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
Ai News
Advertisement
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World
    Hillary Clinton in white pantsuit for Trump inauguration

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel
    Shooting More than 40 Years of New York’s Halloween Parade

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review
    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
Ai News
No Result
View All Result
Home Machine Learning

Building a Command-Line Quiz Application in R

AiNEWS2025 by AiNEWS2025
2025-10-14
in Machine Learning
0
Building a Command-Line Quiz Application in R
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


I science journey a couple of years back, and I realized that most of the experiences I gained tended to revolve around data analysis and theoretical coding.

Looking back, one of the benefits I got from being a computer science major was developing a core understanding of various programming languages.

Although the downside is that you have all these theories, but little to no practice.

With that in mind, I challenged myself to build something using one of the top programming languages in data science: R.

And yes, I know what you might be thinking: why R, and not Python?

Well, stick with me for a minute.

According to a StrataScratch article, nearly 20,000 data professionals were surveyed, and 31% reported using R daily.

To me, that 31% is a huge slice of the pie, and it got me thinking.

If R is powerful enough to crunch millions of rows of data, why dont I also use it to practice the fundamentals of programming in relation to data science?

Sometimes, the best way to grow as a data scientist may not be by jumping straight into machine learning libraries or analyzing large datasets. It could also come from embracing constant learning and gradually expanding your skills.

That’s what inspired me to create this project, a command-line quiz application in R, right inside the terminal.

It’s simple, but it teaches the same skills you’ll need when building more complex data pipelines, such as control flow, input handling, and modular functions.

In this article, I’ll walk you through the process step by step, sharing not only the code but also the lessons I picked up along the way.


Handling User Input

I got a little emotional here because this took me back to the first time I used readline() in R. Seeing the program “wait” for me to type something felt like I was having a conversation with my code.

Okay, more coding, less nostalgia.

Like most projects, I started small, beginning with just one question and one answer check.

# First experiment: single question with basic input handling
# Bug note: without tolower(), "Abuja" vs "abuja" caused a mismatch
answer 

This snippet looks simple, but it introduces two important ideas:

  • readline() allows interactive input in the console.
  • tolower() + trimws() helps normalize responses (avoiding mismatches due to case or extra spaces).

When I first tried this, I typed “Abuja ” with a trailing space, and it marked me wrong. With that, I realized that cleaning input is just as important as collecting it.

Building Logic with Control Flow and Functions

Initially, I stacked everything inside a single block of if statements, but it quickly became messy.

Not my greatest call, to be honest.

It quickly reminded me of structured programming, where breaking things into functions often makes the code cleaner and easier to read.

# Turned the input logic into a reusable function
# Small bug fix: added trimws() to remove stray spaces in answers
ask_question 

What felt most fulfilling about using functions wasn’t just the cleaner code, but the realization that I was finally practicing and sharpening my programming skills.

Data science is kind of like learning a TikTok dance; you only really get it once you start practicing the moves yourself.

Creating a Question Bank

To scale the quiz, I needed a way to store multiple questions, instead of just hardcoding one at a time. I mean, you could do that, but it’s not really efficient.

Now that’s the beauty of R’s list structure; it was flexible enough to hold both the questions and their answers, which made it a perfect fit for what I was building.

# Question bank: keeping it simple with a list of lists
# Note: started with just 2 questions before scaling up
quiz_questions 

In my quest to seek feedback, I shared this with a friend who suggested adding categories (like “Geography” or “R Programming”), which could actually be a good improvement for later.

Running the Quiz (Looping Through Questions)

Now comes the fun part: looping through the question bank, asking each question, and keeping track of the score. This loop is the engine that drives the entire application.

To make this clearer, here’s a simple flowchart to illustrate what I’m saying:

Flowchart (Image by Author)

With this structure in mind, here’s how it looks in code:

# Running through the quiz with a score counter
# (I started with a for loop before wrapping this into run_quiz())
score 

Final Touches

To polish things up, I wrapped the logic into a run_quiz() function, making the program reusable and easy to understand.

# Wrapped everything in a single function for neatness
# This version prints a welcome message and total score
run_quiz 

At this point, the app felt complete. It welcomed the player, asked a series of questions, and displayed the final score with a celebratory message.

Neat.

Sample Run

Here’s what it looked like when I played it in the R console:

👋 Welcome to the R Quiz Game!
You will be asked 2 questions. Good luck!

What is the capital of Nigeria?
Your answer: Abuja
✅ Correct!

Which package is commonly used for data visualization in R?
Your answer: ggplot
❌ Wrong. The correct answer is: ggplot2

🎉 Final score: 1 out of 2

Conclusion and Takeaways

Looking back, this small project taught me lessons that directly apply to larger data science workflows. A command-line quiz game in R might sound trivial, but trust me, it is a powerful exercise.

If you’re learning R, I recommend trying your own version. Add more questions, and shuffle them. To push yourself more, you could even time-limit responses.

Programming isn’t about reaching a finish line; it’s about staying on the learning curve. Small projects like this keep you moving forward— one function, one loop, one challenge at a time.

Source link

#Building #CommandLine #Quiz #Application

Tags: codingdata sciencemachine learningProgrammingRR Programming
Previous Post

Hackers can steal 2FA codes and private messages from Android phones

Next Post

Mastercard unveils platform to boost payment approval rates

AiNEWS2025

AiNEWS2025

Next Post
Mastercard unveils platform to boost payment approval rates

Mastercard unveils platform to boost payment approval rates

Stay Connected test

  • 23.9k Followers
  • 99 Subscribers
  • Trending
  • Comments
  • Latest
A tiny new open source AI model performs as well as powerful big ones

A tiny new open source AI model performs as well as powerful big ones

0
Water Cooler Small Talk: The Birthday Paradox 🎂🎉 | by Maria Mouschoutzi, PhD | Sep, 2024

Water Cooler Small Talk: The Birthday Paradox 🎂🎉 | by Maria Mouschoutzi, PhD | Sep, 2024

0
Ghost of Yōtei: The acclaimed Ghost of Tsushima is getting a sequel

Ghost of Yōtei: The acclaimed Ghost of Tsushima is getting a sequel

0
Best Headphones for Working Out (2024): Bose, Shokz, JLab

Best Headphones for Working Out (2024): Bose, Shokz, JLab

0
Can One AI Platform Replace Your Creative Tool Stack?

Can One AI Platform Replace Your Creative Tool Stack?

2026-01-10
Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

2026-01-10
Conservative lawmakers want porn taxes. Critics say they’re unconstitutional.

Conservative lawmakers want porn taxes. Critics say they’re unconstitutional.

2026-01-10
Elon Musk says he’s going to open-source the new X algorithm next week

Elon Musk says he’s going to open-source the new X algorithm next week

2026-01-10

Recent News

Can One AI Platform Replace Your Creative Tool Stack?

Can One AI Platform Replace Your Creative Tool Stack?

2026-01-10
Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

2026-01-10
Conservative lawmakers want porn taxes. Critics say they’re unconstitutional.

Conservative lawmakers want porn taxes. Critics say they’re unconstitutional.

2026-01-10
Elon Musk says he’s going to open-source the new X algorithm next week

Elon Musk says he’s going to open-source the new X algorithm next week

2026-01-10
Footer logo

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow Us

Browse by Category

  • AI & Cloud Computing
  • AI & Cybersecurity
  • AI & Sentiment Analysis
  • AI Applications
  • AI Ethics
  • AI Future Predictions
  • AI in Education
  • AI in Fintech
  • AI in Gaming
  • AI in Healthcare
  • AI in Startups
  • AI Innovations
  • AI News
  • AI Research
  • AI Tools & Automation
  • Apps
  • AR/VR & AI
  • Business
  • Deep Learning
  • Emerging Technologies
  • Entertainment
  • Fashion
  • Food
  • Gadget
  • Gaming
  • Health
  • Lifestyle
  • Machine Learning
  • Mobile
  • Movie
  • Music
  • News
  • Politics
  • Review
  • Robotics & Smart Systems
  • Science
  • Sports
  • Startup
  • Tech
  • Travel
  • World

Recent News

Can One AI Platform Replace Your Creative Tool Stack?

Can One AI Platform Replace Your Creative Tool Stack?

2026-01-10
Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

Federated Learning, Part 1: The Basics of Training Models Where the Data Lives

2026-01-10
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.