Last active
June 23, 2025 15:30
-
-
Save nitinstp23/81dee3a1e58cfe83099025ab54e44b46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Question struct { | |
description string | |
qType string | |
options []string | |
} | |
func printQuiz(questions []Question) { | |
for _, question := range questions { | |
switch question.qType { | |
case "text": | |
fmt.Println(question.description) | |
fmt.Println("Answer: ____________________") | |
case "boolean": | |
fmt.Println(question.description) | |
for i, option := range question.options { | |
fmt.Printf("%d. %s\n", i+1, option) | |
} | |
case "multipleChoice": | |
fmt.Println(question.description) | |
for i, option := range question.options { | |
fmt.Printf("%d. %s\n", i+1, option) | |
} | |
} | |
fmt.Println() | |
} | |
} | |
func main() { | |
questions := []Question{ | |
{ | |
description: "What is your name?", | |
qType: "text", | |
}, | |
{ | |
description: "Do you like programming?", | |
qType: "boolean", | |
options: []string{"True", "False"}, | |
}, | |
{ | |
description: "What is your favorite programming language?", | |
qType: "multipleChoice", | |
options: []string{"GoLang", "Python", "Java", "Typescript"}, | |
}, | |
} | |
printQuiz(questions) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactored code following SOLID design