Calculating and Formatting Dynamics
Tâche
Swipe to start coding
As of 2020, the USA population was 331002651, of which 273975139 - urban population. The Urban population (%) is the proportion of the urban population to the total. Your tasks are:
- Print total and urban populations with commas every thousand;
- Calculate urban population (%), and print the result in the following format:
45.653%
.
Solution
# Variables
population = 331002651
urban_pop = 273975139
# Formatting
print("USA Population: {0:,}, {1:,} of them - urban population.".format(population, urban_pop))
print("Urban population: {:.3%}".format(urban_pop/population))
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 9
# Variables
population = 331002651
urban_pop = 273975139
# Formatting
print("USA Population: {___}, {___} of them - urban population.".format(___, ___))
print("Urban population: {___}".format(___/___))