Why my solution is not passing the Test?

Screen Link:

https://app.dataquest.io/c/62/m/331/python-data-analysis-basics/8/formatting-numbers-inside-strings

My Code:

pop_millions = [
    ["China", 1379.302771],
    ["India", 1281.935991],
    ["USA",  326.625791],
    ["Indonesia",  260.580739],
    ["Brazil",  207.353391],
]

template = "The population of {country} is {number:,.2f} million"
for i in pop_millions:
    state = i[0]
    population = i[1]
    output = template.format(country=state,    number=population)
    
print(output)

What I expected to happen:

  • The population of China is 1,379.30 million
  • The population of India is 1,281.94 million
  • The population of USA is 326.63 million
  • The population of Indonesia is 260.58 million

What actually happened:

- actual + expected

+ The population of China is 1,379.30 million
+ The population of India is 1,281.94 million
+ The population of USA is 326.63 million
+ The population of Indonesia is 260.58 million
  The population of Brazil is 207.35 million

The output of your code didn't match what we expected.

Hi together,

i can’t see what is the issue here. Is my complete Code false or does it fails only at the Brazil output? I don’t get a red line where my Code is buggy.

To check i executed my Code also on Pythontutor and the Output seems fine to me.
Hope somebody can help me here.

Thanks.

Simo

The output of your code is. . .

image

The lack of red lines tell us that you didn’t print anything that wasn’t supposed to be there.
The green lines tell us that we expected those lines, but they weren’t output.
The gray (or whatever color it is) tells us that that line was printed correctly.

So, you’re only printing one of the lines. Why is that?

1 Like

Thanks for checking Bruno.
I think after your hint that the problem is that the print Output is not in the Loop?

1 Like

Exactly!

1 Like

Love that open questions that directs me to the right answer :grinning_face_with_smiling_eyes: Thanks Bruno!:grinning:

1 Like