








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









// (double forward slash) # (pound symbol)
% (percent symbol)✔✔ Correct answer # (pound symbol)
Float String Boolean✔✔ Correct answer Float
An iterable object A number A variable name✔✔ Correct answer An iterable object
for loop infinite loop do-while loop✔✔ Correct answer for loop
indented code block A variable and a return statement A counter and a break statement An iterator and a list✔✔ Correct answer A condition and an indented code block
break stop end✔✔ Correct answer break
index of the current element
move goto cd nav✔✔ Correct answer cd
Python shell Text editor File explorer Debugger✔✔ Correct answer Python shell
example, files 'document.pdf' and 'image.png' would return 'pdf' and 'png', respectively. Which slicing approach would work for either of the provided files? filename[✔✔ Correct answer9] filename[9✔✔ Correct answer] filename[-3✔✔ Correct answer] filename[✔✔ Correct answer-3]✔✔ Correct answer filename[-3✔✔ Correct answer]
python programming'? 8
9
1
2 ✔✔ Correct answer 9
number, and returns a new list that appends the new number to the end of the list. For example, add_item([1, 2, 3], 4) should return [1, 2, 3, 4].
def add_item(numeric_list, new_number)✔✔ Correct answer
✔✔ Correct answer add_item([1, 2, 3], 4) should return [1, 2, 3, 4]
pass✔✔ Correct answer def add_item(numeric_list, new_number)✔✔
Correct answer numeric_list.append(new_number) return numeric_list
name, and a new grade, then updates that student's grade and returns the dictionary.
For example, update_grade({"Alice"✔✔ Correct answer 85, "Bob"✔✔ Correct answer 90}, "Alice", 95) should
return
{"Alice"✔✔ Correct answer 95, "Bob"✔✔ Correct answer 90}.
def update_grade(grades, student, new_grade)✔✔ Correct answer
Example✔✔ Correct answer update_grade({"Alice"✔✔ Correct answer 85, "Bob"✔✔ Correct answer 90}, "Alice", 95)
Correct answer 90} pass✔✔ Correct answer def update_grade(grades,
student, new_grade)✔✔ Correct answer
grades[student] = new_grade return grades
for name in ['Alice', 'Bob', 'Carol']✔✔ Correct answer
for name with ['Alice', 'Bob', 'Carol']✔✔ Correct answer
for name from ['Alice', 'Bob', 'Carol']✔✔ Correct answer
for name = ['Alice', 'Bob', 'Carol']✔✔ Correct answer for name in ['Alice', 'Bob', 'Carol']✔✔ Correct answer
while len(grades) > 0✔✔ Correct
answer for grade in grades✔✔
and decimal values.
Which conditional statement should be placed inside the loop?
if number > 0✔✔ Correct answer
if number != 0✔✔ Correct answer
if number < 0✔✔ Correct answer
if number >= 1 ✔✔ Correct answer if number > 0✔✔ Correct answer
number.
For example, double_number(5) should return 10.
def double_number(num)✔✔ Correct answer
Correct answer def double_number(num)✔✔ Correct answer return num * 2
parameter so it can be called with or without an argument.
def greet_with_default(name)✔✔ Correct answer
otherwise.
def is_positive(number)✔✔ Correct answer
pass✔✔ Correct answer def password_strength(password)✔✔ Correct answer
if len(password) < 8✔✔ Correct answer
return "Weak"
has_letter = False has_number = False
for char in password✔✔ Correct answer
if char.isalpha()✔✔ Correct answer
has_letter = True elif char.isdigit()✔✔ Correct answer has_number = True
if has_letter and has_number✔✔ Correct answer
return "Strong" else✔✔
Correct answer return "Weak"
formula✔✔ Correct answer F = C * 9/5 + 32.
For example, convert_temperature(0) should return 32.0. def convert_temperature(celsius)✔✔ Correct answer
pass✔✔ Correct answer def convert_temperature(celsius)✔✔ Correct answer
return celsius * 9 / 5 + 32
def get_last_character(text)✔✔ Correct answer
return text[len(text)]✔✔ Correct answer def get_last_character(text)✔✔
Correct answer return text[-1]
Tip✔✔ Correct answer Correctly returning the larger of two numbers using if-else You can use
either approach✔✔ Correct answer
Correct answer if a < b✔✔ Correct answer return b else✔✔ Correct answer
return a
if a > b✔✔ Correct answer
return a else ✔✔ Correct answer return b
Key point✔✔ Correct answer The if condition and the corresponding return statements must align so the larger number is returned. Swapping the comparison requires
swapping the return values accordingly.