• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 5 pages
Exam (elaborations)

D522 - Coding Problems Question with Verified Correct Answers

Document preview thumbnail
Preview 2 out of 5 pages

D522 - Coding Problems Question with Verified Correct Answers

Content preview

D522 - Coding Problems Question with Verified
Correct Answers
Code Problem: Create a function named add_numbers that returns the sum of a and b.

Answer: def add_numbers(a, b):\n return a + b

Code Problem: Create a function named minutes_to_hours that converts minutes to

hours.

Answer: def minutes_to_hours(minutes):\n return minutes / 60

Code Problem: Create a function named is_adult that returns True if age is 18 or older.

Answer: def is_adult(age):\n return age >= 18

Code Problem: Create a function named check_temp that returns "Hot" if temp is

greater than 80, otherwise return "Not hot".

Answer: def check_temp(temp):\n if temp > 80:\n return "Hot"\n else:\n return "Not hot"

Code Problem: Create a function named check_access that returns "Allowed" only if

has_id is True and age is 18 or older.

Answer: def check_access(age, has_id):\n if age >= 18 and has_id == True:\n return

"Allowed"\n else:\n return "Denied"

Code Problem: Create a function named count_to_five that prints numbers 1 through 5

using a while loop.

Answer: def count_to_five():\n count = 1\n while count <= 5:\n print(count)\n count += 1

Code Problem: Create a function named get_high_values that returns values greater

than 90 from a list.

, Answer: def get_high_values(nums):\n high_values = []\n for num in nums:\n if num > 90:\n

high_values.append(num)\n return high_values

Code Problem: Create a function named get_high_indices that returns the indexes of

values greater than 90.

Answer: def get_high_indices(nums):\n indices = []\n for i in range(len(nums)):\n if nums[i]

> 90:\n indices.append(i)\n return indices

Code Problem: Create a function named first_item that returns the first item in a list.

Answer: def first_item(items):\n return items[0]

Code Problem: Create a function named last_item that returns the last item in a list.

Answer: def last_item(items):\n return items[-1]

Code Problem: Create a function named add_item that adds item to a list and returns

the updated list.

Answer: def add_item(items, item):\n items.append(item)\n return items

Code Problem: Create a function named update_name that changes the "name" value

in a dictionary.

Answer: def update_name(user, new_name):\n user["name"] = new_name\n return user

Code Problem: Create a function named get_status that returns the value stored under

the "status" key.

Answer: def get_status(log):\n return log["status"]

Code Problem: Create a function named format_rgb that accepts a list like [255, 0, 100]

and returns "rgb(255,0,100)".

Document information

Uploaded on
September 15, 2026
Number of pages
5
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$11.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KenAli
2.6
(18)
Sold
125
Followers
5
Items
26693
Last sold
4 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions