Comments (4)
There are a few ways you could do this. One would be to add the question to the back of the slice of questions and to update the for loop that iterates over all questions to check its length every pass. Do you have a need for this? If you have some code where you are trying you can post it and I'll try to help out.
from quiz.
Yes, using it myself for language learning. Revising the answers i have gotten wrong would help alot! I am currently using csos95’s implementation. Only thing i have changed is removing the time limit flag and channel.
I did make an attempt at this before. But all I could come up with is to print the wrong ones at the end of the quiz using bytes.Buffer.
But adding the adding them back to the slice would be more.... intuitive.
from quiz.
In my implementation I use a map to store the question and answer pairs.
This gives me a randomized ordering when I range over them, but also means that new items can't simply be added inside the loop because there is no guarantee they would be ranged over.
To re-ask incorrect questions I would add incorrect questions to a second map, swap the qaPair map with this second map, and loop over the part that asks questions until the qaPair map is empty.
// loop until the map is empty
for len(qaPair) != 0 {
// a second map to store incorrect questions
qaPairIncorrect := make(map[string]string, 0)
// iteration order for maps in go is randomized so the questions won't be in the same order every time
for question, answer := range qaPair {
qNum++
// ask a question
fmt.Printf("Problem #%d: %s = ", qNum, question)
// get an answer
scanner.Scan()
userAnswer = scanner.Text()
// trim leading and trailing whitespace
userAnswer = strings.TrimSpace(userAnswer)
userAnswer = strings.ToLower(userAnswer)
answer = strings.ToLower(answer)
// check the answer
if answer == userAnswer {
numCorrect++
} else {
// if it was incorrect, add it to the second map
qaPairIncorrect[question] = answer
}
}
// replace the first map with the second
qaPair = qaPairIncorrect
}
This breaks the last print statement showing the score so I would also change the last argument from len(qaPair)
to qNum
from quiz.
@csos95 Thanks for chiming in 👍
@veganexe if you need more help let me know, but it looks like the code sample Christopher gave should help get you going 😄
from quiz.
Related Issues (12)
- Release this exercise
- panic: runtime error: index out of range [1] with length 1 HOT 1
- Creating a channel inside the loop? HOT 1
- Goroutine for timer HOT 1
- Quiz
- Project 1 HOT 1
- Create a student example HOT 2
- Incorrect problem.csv link on Quiz mainpage HOT 1
- Create a student example
- goroutine leak - kind of... HOT 3
- Timeout for each question HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quiz.