Write a function, display_user_books, that takes a user and the borrowed dictionary,
and prints the books borrowed by that user. Example:
>>> borrowed = {'Alice': ['1984']}
>>> display_user_books("Alice", borrowed)
Alice has borrowed:
- 1984
>>> borrowed = {}
>>> display_user_books("Alice", borrowed)
Alice has not borrowed any books.
def coldest_city(cities):
coldest = cities[0]
for city, temp in cities:
if temp < coldest[1]:
coldest = (city, temp)
return coldest[0]
cities = [("Tirane", 35), ("Prishtine", 29), ("Shkup", 30)]
coldest = coldest_city(cities)
Given the above script:
| What is the value of coldest: | ||
| What is the value of city during the first iteration of the loop: | ||
| What is the value of temp during the second iteration of the loop: |
integers = [4, 44, 333]
Print elements of integers, one per line, using for.
Write a function, suggest_best_time, that takes a dictionary, members,
and returns the hour when the most members are available.
If there is a tie, return the earliest hour. Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> suggest_best_time(members)
10
Write a function, return_book(user: str, book: str, books: list[str], borrowed: dict[str, str]),
that moves a book from a user's borrowed list back to the available books.
Return a message about the action. Example:
>>> books = ["1984", "The Hobbit"]
>>> borrowed = {'Alice': ['1984']}
>>> print(return_book("Alice", "1984", books, borrowed))
Book 1984 returned by Alice.
>>> print(return_book("Alice", "The Hobbit", books, borrowed))
Alice did not borrow 'The Hobbit.
Create two lists and assign them to a and b respectively.
Concatenate a and b and assign it to c.
Repeat c 3 times and reassign.
Print c.
d = [2, 2, 1] d.append(4) d.sort() t = d.extend([1, 2])
What is the value of d and t at the end of execution of the above program?
| d: | ||
| t: |
def dosmth(lst):
for index in range(len(lst) - 1):
lst[index] = lst[index + 1]
lst[-1] = lst[0]
nums = [1, 2, 3, 4]
dosmth(nums)
What is the value of nums at the end of execution of the above script?
Complete execution flow of the following program
def capitalize_all(t): res = [] for s in t: res.append(s.capitalize()) return res
Complete execution flow of the following program
t = ['pse', 'po', 'ani'] print(t.remove('pse'))