beginner Exercises
Fun, bite-sized challenges to learn Go basics and logic. Try experimenting with user input, conditionals, loops, and basic data structures. You’ll get a good feel for Go syntax and flow!
- Create a program that greets the user based on the time of day (Good morning, Good afternoon, Good evening).
- Simulate a dice roll using `rand.Intn()` and print the result.
- Ask the user for their favorite programming language and respond differently if it is “Go”.
- Convert a distance in kilometers to miles (1 km ≈ 0.621 miles) and print both values.
- Create a program that splits a restaurant bill among friends evenly, rounding properly.
- Write a program that determines whether a given number is even or odd using conditionals.
- Build a small “quote of the day” app that randomly picks from a list of inspirational quotes.
- Use a `for` loop to print the multiplication table for a number entered by the user.
- Create a slice of grocery items, add a few new items, remove one, and print the updated list.
- Write a function that searches for a given city name in a slice of cities and prints whether it was found.
- Implement a simple calculator that supports +, -, *, and / operations using user input.
- Write a function `reverseString(s string) string` and test it with different inputs.
- Create a “guess the number” game where the computer picks a number and the user guesses until correct.
- Define a `Person` struct with `Name` and `Age`, and print personalized greetings using it.
- Write a recursive function that computes the nth Fibonacci number.
- Make a simple to-do list program that lets the user add and display tasks (store them in a slice).
- Use a map to associate country names with their capitals and allow the user to look up any capital.
- Define an interface `Animal` with a method `Speak()`, and create structs for Dog, Cat, and Cow implementing it.