0
0
Goprogramming~20 mins

Short variable declaration in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Short Variable Declaration in Go
๐Ÿ“– Scenario: Imagine you are writing a simple Go program to store and display information about a fruit.
๐ŸŽฏ Goal: You will create variables using Go's short variable declaration syntax and print their values.
๐Ÿ“‹ What You'll Learn
Use short variable declaration to create variables
Use the exact variable names and values given
Print the variables to show their values
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Short variable declaration is a common and concise way to create variables in Go programs, useful in many real-world applications like data processing and web development.
๐Ÿ’ผ Career
Understanding short variable declaration is essential for Go developers to write clean and efficient code, a skill valued in software engineering jobs.
Progress0 / 4 steps
1
Create variables using short variable declaration
Use Go's short variable declaration to create a variable fruit with the value "apple" and a variable quantity with the value 5.
Go
Need a hint?

Use := to declare and assign variables in one step.

2
Add a variable for price
Add a short variable declaration for a variable price with the value 0.99.
Go
Need a hint?

Remember to use := for short variable declaration.

3
Calculate total cost
Create a new variable totalCost using short variable declaration that multiplies quantity and price.
Go
Need a hint?

Convert quantity to float64 before multiplying with price.

4
Print the total cost
Use fmt.Printf to print the message: Total cost for 5 apples is $4.95 using the variables quantity, fruit, and totalCost. Format totalCost to two decimal places.
Go
Need a hint?

Use fmt.Printf with %d for integers, %s for strings, and %.2f for floating numbers with two decimals.