Skip to content

Instantly share code, notes, and snippets.

View cibofdevs's full-sized avatar
💼
Working From Home

Ahmad Wijaya cibofdevs

💼
Working From Home
View GitHub Profile
import requests_with_caching
import json
def get_movies_from_tastedive(title):
url = 'https://tastedive.com/api/similar'
param = {}
param['q']= title
param['type']= 'movies'
param['limit']= 5
# 1. The textfile, travel_plans.txt, contains the summer travel plans for someone with some commentary.
# Find the total number of characters in the file and save to the variable num.
fileref = open("travel_plans.txt","r")
num = 0
for i in fileref:
num += len(i)
fileref.close()
# 2. We have provided a file called emotion_words.txt that contains lines of words that describe emotions.
# The variable sentence stores a string.
# Write code to determine how many words in sentence start and end with the same letter, including one-letter words.
# Store the result in the variable same_letter_count.
sentence = "students flock to the arb for a variety of outdoor activities such as jogging and picnicking"
# Write your code here.
same_letter_count = sum(w[0] == w[-1] for w in sentence.split())
print(same_letter_count)
# 1. The dictionary Junior shows a schedule for a junior year semester.
# The key is the course name and the value is the number of credits.
# Find the total number of credits taken this semester and assign it to the variable credits.
# Do not hardcode this – use dictionary accumulation!
Junior = {'SI 206':4, 'SI 310':4, 'BL 300':3, 'TO 313':3, 'BCOM 350':1, 'MO 300':3}
credits = 0
for v in Junior.values():
credits += v
print(credits)
# 1. Below are a set of scores that students have received in the past semester.
# Write code to determine how many are 90 or above and assign that result to the value a_scores.
scores = "67 80 90 78 93 20 79 89 96 97 92 88 79 68 58 90 98 100 79 74 83 88 80 86 85 70 90 100"
scores_split = scores.split(" ")
a_scores = 0
for x in scores_split:
x = float(x)
if x >= 90:
a_scores += 1
# Write one for loop to print out each character of the string my_str on a separate line.
my_str = "MICHIGAN"
for i in range(len(my_str)):
print(my_str[i])
# 1. Create a function called mult that has two parameters, the first is required and should be an integer,
# the second is an optional parameter that can either be a number or a string but whose default is 6.
# The function should return the first parameter multiplied by the second.
def mult(a, b=6):
return a * b
# 2. The following function, greeting, does not work. Please fix the code so that it runs without error.
# This only requires one change in the definition of the function.
# 1. The variable nested contains a nested list. Assign ‘snake’ to the variable output using indexing.
nested = [['dog', 'cat', 'horse'], ['frog', 'turtle', 'snake', 'gecko'], ['hamster', 'gerbil', 'rat', 'ferret']]
output = nested[1][2]
print(output)
# 2. Below, a list of lists is provided. Use in and not in tests to create variables with Boolean values.
# See comments for further instructions.
lst = [['apple', 'orange', 'banana'], [5, 6, 7, 8, 9.9, 10], ['green', 'yellow', 'purple', 'red']]

Error The attempted operation is not supported for the type of object referenced when using virtual network adapter on wsl2

Try run this commands:

wsl --shutdown
netsh winsock reset

If execution success, The message like this:

# Create an empty string and assign it to the variable lett.
# Then using range, write code such that when your code is run, lett has 7 b’s ("bbbbbbb").
lett = ''
for i in range(7):
lett += 'b'
print(lett, end='')