Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the variable name using string interpolation.
C Sharp (C#)
string name = "Alice"; Console.WriteLine($"Hello, [1]!");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable name inside the braces, which prints the word instead of the value.
Using a different variable name that does not exist.
✗ Incorrect
Using $"Hello, {name}!" inserts the value of the variable
name into the string.2fill in blank
mediumComplete the code to format the number score with two decimal places using string interpolation.
C Sharp (C#)
double score = 95.6789; Console.WriteLine($"Score: [1]{score}");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using :F1 which shows only one decimal place.
Using :P2 which formats as percentage.
Using :N2 which adds commas but also shows decimals.
✗ Incorrect
The format specifier
:F2 formats the number with two decimal places.3fill in blank
hardFix the error in the code to correctly align the text to the right with width 10 using string interpolation.
C Sharp (C#)
string word = "Hi"; Console.WriteLine($"[1],10}");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable name, which prints the word 'word' instead of the variable value.
Using a capitalized variable name that does not exist.
✗ Incorrect
Inside the braces, use the variable name
word without quotes to align it right with width 10.4fill in blank
hardFill both blanks to create a formatted string that shows the price with 2 decimals and left-aligns the item in 15 spaces.
C Sharp (C#)
string item = "Apple"; double price = 1.2345; string output = $"[1],-15} costs [2]:F2}";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
price in the first blank which is a number, not a string.Using
item.ToUpper() which changes the text but is not required.Using
price.ToString() which is unnecessary inside interpolation.✗ Incorrect
Use
item with ,-15 to left-align and price with :F2 to format decimals.5fill in blank
hardFill all three blanks to create a string that shows the uppercase city, the temperature with 1 decimal, and the unit symbol.
C Sharp (C#)
string city = "Paris"; double temperature = 23.456; string unit = "°C"; string report = $"[1]: [2]:F1}[3]";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
city instead of city.ToUpper() for uppercase.Putting quotes around variables inside braces.
Not formatting the temperature to one decimal.
✗ Incorrect
Use
city.ToUpper() for uppercase city, temperature with :F1 for one decimal, and unit for the symbol.