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!

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