Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 3: Open Web Data Compose a function open_url which accepts a string language. open_url should return a str containing the reference language letter frequencies
Exercise 3: Open Web Data Compose a function open_url which accepts a string language. open_url should return a str containing the reference language letter frequencies stored at the URL of the form given below. : #grade def open_url( language ): Open the language URL using 'requests and read the data out via the text attribute. The URL you need is of the form https://raw.githubusercontent.com/UI-CS101/cs101-fa16/master/lab07/language where you'll replace language with the string passed in (think of string format operators). For instance, if language == 'english', then the URL should be https://raw.githubusercontent.com/UI-CS101/cs101-fa16/master/labo7/english Args: string: language name Returns: The text found at the url url_prefix = 'https://raw.githubusercontent.com/UI-CS101/cs101-fa16/master/lab07/' url_suffix = ## YOUR CODE HERE # Construct url here from "url_prefix' and 'Language url = url_prefix + url_suffix # Read the data from the url, using the requests Library's .get() function language_data = requests.get( url ).text # Finally, return the string 'Language_data". return language_data You may edit this cell, and you may use any Language listed above, but the following is provided # test your code here. language = 'polish' open_url(language) # it should pass this test---do NOT edit this cell from numpy import isclose test_ref = open_url('english') assert test_ref.split(' ')[0] == 'A, 8.34%' assert len(test_ref) == 209 print('Success!')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started