This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To complete this assignment, you should use this API endpoint that has a static subset of the Google Data: | |
# http://py4e-data.dr-chuck.net/json? | |
# This API uses the same parameter (address) as the Google API. This API also has no rate limit so you can test as often as you like. | |
# If you visit the URL with no parameters, you get "No address..." response. | |
# To call the API, you need to include a key= parameter and provide the address that you are requesting as the address= parameter that | |
# is properly URL encoded using the urllib.parse.urlencode() function as shown in http://www.py4e.com/code3/geojson.py | |
# Make sure to check that your code is using the API endpoint is as shown above. | |
# Please run your program to find the place_id for this location: University of Akron | |
# Make sure to enter the name and case exactly as above and enter the place_id and your Python code below. Hint: The first seven characters of the place_id are "ChIJbye ..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Data file url: http://py4e-data.dr-chuck.net/comments_1070214.xml | |
#VERSION 1: | |
import urllib.request | |
import xml.etree.ElementTree as ET | |
import ssl | |
# Ignore SSL certificate errors | |
ctx = ssl.create_default_context() | |
ctx.check_hostname = False | |
ctx.verify_mode = ssl.CERT_NONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiples(x): | |
for n in range(100): | |
n = (n*x) | |
if n <= 100: | |
print(n) | |
print(multiples(7)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def student_grade(name, grade): | |
# return "" | |
return "{} received {}% on the exam".format(name, grade) | |
print(student_grade("Reed", 80)) | |
print(student_grade("Paige", 92)) | |
print(student_grade("Jesse", 85)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_power_of(number, base): | |
# Base case: when number is smaller than base. | |
number = number/base | |
if number < base: | |
# If number is equal to 1, it's a power (base**0). | |
return False | |
else: | |
return True | |
# Recursive case: keep dividing number by base. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def digits(n): | |
count = 0 | |
if n == 0: | |
return 1 | |
while (n > 0): | |
count += 1 | |
n = n // 10 | |
return count | |
print(digits(25)) # Should print 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This function prints out a multiplication table (where each number is the result of multiplying the first number of its row by the number at the top of its column). Fill in the blanks so that calling multiplication_table(1, 3) will print out: | |
#1 2 3 | |
#2 4 6 | |
#3 6 9 | |
def multiplication_table(start, stop): | |
for x in range(start,stop+1): | |
for y in range(start,stop+1): | |
print(str(x*y), end=" ") | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def even_numbers(maximum): | |
return_string = "" | |
for x in range(2, maximum + 1, 2): | |
return_string += str(x) + " " | |
return return_string.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#using recursion | |
def sum_positive_numbers(n): | |
if n <= 1: | |
return n | |
return n + sum_positive_numbers(n-1) | |
print(sum_positive_numbers(3)) # Should be 6 | |
print(sum_positive_numbers(5)) # Should be 15 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initials(phrase): | |
words = phrase.split() | |
result = "" | |
for word in words: | |
result += word[0].upper() | |
return result | |
print(initials("Universal Serial Bus")) # Should be: USB | |
print(initials("local area network")) # Should be: LAN | |
print(initials("Operating system")) # Should be: OS |
NewerOlder