192k views
5 votes
Store the amount of the minimum loan in min_loan and the amount of the maximum loan in max_loan Then, store the name of the country that received the largest loan in max_country and the smallest loan in min_country Hint: max and min are built in Python functions that you can use to find the minimum value or maximum value in any sequence.

User Shew
by
4.3k points

1 Answer

3 votes

Answer:

See Explanation

Step-by-step explanation:

The question has missing details;however, I'm able to pick the following points from the question

  • There's supposed to be a list of loan amounts
  • There's also supposed to be a list of countries that took loans. This list will correspond to the loan list

Having said that, the question can be solved in two ways.

  • I prompt the user to enter loan amounts and corresponding country
  • I assume any value for the loan amounts and the country

I'll answer this question using the first method and the solution is as follows (See Comments for line by line explanation):

#This line prompt user for number of countries

n = int(input("Number of countries: "))

#This initializes an empty list for loan amounts

loan_amounts = []

#This initializes an empty list for country

country = []

#The following iteration gets names of countries and their respective loan amounts

for i in range(0,n):

country_name = input("Name of country: ")

loan = int(input("Loan Amount: "))

country.append(country_name)

loan_amounts.append(loan)

#This gets the maximum loan

max_loan = max(loan_amounts)

#This gets the index of the maximum loan

iindex = loan_amounts.index(max_loan)

#This gets the country with the maximum loan

max_country = country[iindex]

#This gets the minimum loan

min_loan = min(loan_amounts)

#This gets the index of the minimum loan

iindex = loan_amounts.index(min_loan)

#This gets the country with the minimum loan

min_country = country[iindex]

#This prints the country with the maximum loan and the loan amount

print(str(max_country)+": "+str(max_loan))

#This prints the country with the minimum loan and the loan amount

print(str(min_country)+": "+str(min_loan))

Store the amount of the minimum loan in min_loan and the amount of the maximum loan-example-1
User Igorushi
by
4.2k points