Я хочу написать программу, которая использует время l oop для суммирования четных целых чисел от 1 до 20. Это мой код в Python IDLE.
#Important Notes
#===============
#You MUST use the following variables
# - total
# - number
#START CODING FROM HERE
#======================
#Set number value
number = 2
total = 0
#Check closest object
def total_num(number):
while number % 2 == 0 and number <=20:
total = total + number
number = number + 2
print('The total is {}'.format(total)) #Modify to display the total
return total #Do not remove this line
#Do not remove the next line
total_num(number)
#output 110
Я получаю следующие ошибки:
total_num(number)
and
total = total + number
UnboundLocalError: local variable 'total' referenced before assignment