Complete the code to handle the exception and to generate 'Error Occurred'
new_string = 'Python'
my_index = 0
try:
while my_index != len(new_string) / 2:
print(new_string[my_index:len(new_string)/2])
my_index += 1
XXX
print('Error Occurred')
,A. except (TypeError, IndentationError):
B. except (IndentationError, AttributeError):
C. except (AttributeError, IndentationError):
D. except (NameError, TypeError):
Give this one a try later!
D. except (NameError, TypeError):
What is the output?
new_list = [0, 1, 2, 3, 4]
print(all(new_list))
print(min(new_list) + max(new_list))
A. True
4
B. False
4
C. False
10
D. True
10
Give this one a try later!
A. True
4
Choose the option that gives ['ABC', 'ABC'] as the output.
A. my_list = ['ABC', 'DEF']
my_list[len(my_list)-1] = 'DEF'
print(my_list)
,B. my_list = ['ABC', 'DEF']
my_list[len(my_list)] = 'ABC'
print(my_list)
C. my_list = ['ABC', 'DEF']
my_list[len[my_list)-1] = 'ABC'
print(my_list)
D. my_list = ['DEF', 'ABC']
my_list[len(my_list)-1] = 'ABC'
print(my_list)
Give this one a try later!
C. my_list = ['ABC', 'DEF']
my_list[len[my_list)-1] = 'ABC'
print(my_list)
Python uses _________ constructs to handle errors during execution.
A. control
B. class method
C. exception-handling
D. conditional
Give this one a try later!
C. exception-handling
Which function is most appropriate to improve the given code?
power_consumption_app1 = 600.85
hours_of_use1 = 12.8
energy_per_day1 = (power_consumption_app1 * hours_of_use1) / 1000
power_consumption_app2 = 1800.45
hours_of_use2 = 0.45
, energy_per_day2 = (....)
power_consumption_app3 = 70
hours_of_use3 = 1.5
energy_per_day3 = (...)
total_energy_consumed = energy_per_day1 + energy_per_day2 + energy_per_day3
print(f'The total energy consumed per day is {total_energy_consumed:f}')
A. def print_power_consumed(total_energy_consumed):
print(total_energy_consumed)
B. def input_values(power, hours):
power = float(input())
hours = float(input())
C. def compute_energy_consumed(power, hours):
return (power * hours) / 1000
D. def compute_total(energy_day1, energy_day2, energy_day3):
return energy_per_day1 + energy_per_day2 + energy_per_day3
Give this one a try later!
C. def compute_energy_consumed(power, hours):
return (power * hours) / 1000
Given that my_val is a list of float values, which of the following is an example of a
built-in function?
A. my_val.capitalize()
B. my_val.title()
C. len(my_val)
D. average(my_val)
Give this one a try later!
new_string = 'Python'
my_index = 0
try:
while my_index != len(new_string) / 2:
print(new_string[my_index:len(new_string)/2])
my_index += 1
XXX
print('Error Occurred')
,A. except (TypeError, IndentationError):
B. except (IndentationError, AttributeError):
C. except (AttributeError, IndentationError):
D. except (NameError, TypeError):
Give this one a try later!
D. except (NameError, TypeError):
What is the output?
new_list = [0, 1, 2, 3, 4]
print(all(new_list))
print(min(new_list) + max(new_list))
A. True
4
B. False
4
C. False
10
D. True
10
Give this one a try later!
A. True
4
Choose the option that gives ['ABC', 'ABC'] as the output.
A. my_list = ['ABC', 'DEF']
my_list[len(my_list)-1] = 'DEF'
print(my_list)
,B. my_list = ['ABC', 'DEF']
my_list[len(my_list)] = 'ABC'
print(my_list)
C. my_list = ['ABC', 'DEF']
my_list[len[my_list)-1] = 'ABC'
print(my_list)
D. my_list = ['DEF', 'ABC']
my_list[len(my_list)-1] = 'ABC'
print(my_list)
Give this one a try later!
C. my_list = ['ABC', 'DEF']
my_list[len[my_list)-1] = 'ABC'
print(my_list)
Python uses _________ constructs to handle errors during execution.
A. control
B. class method
C. exception-handling
D. conditional
Give this one a try later!
C. exception-handling
Which function is most appropriate to improve the given code?
power_consumption_app1 = 600.85
hours_of_use1 = 12.8
energy_per_day1 = (power_consumption_app1 * hours_of_use1) / 1000
power_consumption_app2 = 1800.45
hours_of_use2 = 0.45
, energy_per_day2 = (....)
power_consumption_app3 = 70
hours_of_use3 = 1.5
energy_per_day3 = (...)
total_energy_consumed = energy_per_day1 + energy_per_day2 + energy_per_day3
print(f'The total energy consumed per day is {total_energy_consumed:f}')
A. def print_power_consumed(total_energy_consumed):
print(total_energy_consumed)
B. def input_values(power, hours):
power = float(input())
hours = float(input())
C. def compute_energy_consumed(power, hours):
return (power * hours) / 1000
D. def compute_total(energy_day1, energy_day2, energy_day3):
return energy_per_day1 + energy_per_day2 + energy_per_day3
Give this one a try later!
C. def compute_energy_consumed(power, hours):
return (power * hours) / 1000
Given that my_val is a list of float values, which of the following is an example of a
built-in function?
A. my_val.capitalize()
B. my_val.title()
C. len(my_val)
D. average(my_val)
Give this one a try later!