Language: Python
Topic: APIs and JSON
Function name: can_visit
Parameters: country_code (str), langList (list of strings )
Return: boolean
Description: You are looking for a country to visit for SB2K19 and want to ensure that you know how to speak at least one of the languages spoken in that country. Given a country_code (str), a three - letter code representing the country you want to visit, and a langList (list), a list of the names of the languages you know how to speak, develop a function that returns True if you can speak at least one of the languages spoken in the country represented by country _code or return False if you cannot speak any of the languages spoken in the country represented by country_code.
Hint: Using the Languages endpoint for this function will not work because the languages are passed in by their name not by their code.
Tes t Cases:
>>> result = can_visit("LBN", [“Python”, "Chinese", "Java", "French"]) >>> print(result)
True
>>> result = can_visit("PRT", ["Spanish", "English", "Arabic"])
>>> print(result)
False
https://restcountries.eu
Hello there, below is the code and screenshot
----------------------------------------------------------------------------------------------------------
import requests
def can_visit(country_code, langList):
url =
"https://restcountries.eu/rest/v2/alpha?codes={};lang/es".format(country_code.lower())
r = requests.get(url)
data_dict = r.json()[0]
lan_list = []
for lan in data_dict['languages']:
lan_list.append(lan['name'].lower())
for lan in langList:
if lan.lower() in lan_list:
return
True
return False
if __name__ == '__main__':
code = "LBN"
langList = ["Python", "Chinese", "Java",
"French"]
print(code)
result = can_visit(code, langList)
print(result)
code = "PRT"
langList = ["Spanish", "English", "Arabic"]
print(code)
result = can_visit(code, langList)
print(result)
----------------------------------------------------------------------------------------

Language: Python Topic: APIs and JSON Function name: can_visit Parameters: country_code (str), langList (list of strings...
Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list of tuples Description: You are working on a project for your Demography class and you are tasked with finding the top num most populous countries in a given region . Instead of looking up on the Internet, you decide to apply your CS1301 knowledge of APIs and write a function to solve the problem for you. Develop a function that takes in a region...
Language: Python Topic: Tuples Function name : todo_tuple Parameters : todo (list of tuples of strings), completed (list of strings) Returns: final_list (list) Description : Write a function that takes in a list of tuples of strings that represents the work you have to do in each class, and a list of strings that represent the work you have already completed. Each tuple in the todo list represents the work for a single class. For this function, go through the...
Language: Python Topic: Try/Except Function name : add_divide Parameters : list of ints, int Returns: float Description: Given a list of integers and a number, you want to add the numbers in the list to a total value by iterating through the given list. However, when the index you are at is divisible by the integer passed in, you must instead divide the current total by the element at that index. You must be careful when dividing the total (you...
Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...
Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are 0), int (day of the month 1 to 28) Returns: dates: list of tuples Description: Imagine that you have a favorite weekday, and want to see if certain days fall on that weekday. Using the calendar module from the Python standard library , write a function which takes in a list of tuples formatted like [(month, year), etc.], your favorite weekday, and a...
python
Days of the Week Function Name: days_of_the_week() Parameters: list of birthdays ( list ), year (int ) Returns: list of names ( list ) Description: You and your friends all want to celebrate your birthdays together, but you don't want to stay up late on a school night. Write a function that takes in a list of tuples formatted as (day ( int ), month ( int ), name (string)), and a year ( int ). Use Python's calendar...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...
Python
String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...
python
Function Name: find_me Parameters: a dictionary of strings mapping to strings ( dict ), person1 ( str), person2 (str) Returns: number of people in between the first and last person ( int ) Description: Given a dictionary and two names, find the number of people in between them. The dictionary maps a person ( key ) to the person ( value ) in front of them in a line. If person2 is the value of the personi key, then...
Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should be posted every mile on a given street. You are given a list of 0s & 1s, where each number represents a quarter of a mile. Thus, every 4 zeroes requires a speed sign. However, a 1 indicates an intersection, and each intersection is automatically required to have a speed limit sign. A sign for each mile proceeds as usual after the intersection. Your...