Ich versuche, ein einfaches Array-Programm zu erstellen und die Array-Elemente auszudrucken, bekomme aber sofort einen Fehler, nachdem ich Mitarbeiter 2 eingegeben habe: IndexError: Listenzuweisungsindex außerhalb des Bereichs.Listenzuweisungsindex außerhalb des Bereichsfehler
#Create constant for the number of employees.
SIZE = 3
#Create an array to hol the number of hours worked by each employee.
hours = [SIZE]
#Get the hours worked by employee 1.
hours[0] = int(input("Enter the hours worked by employee 1: "))
#Get the hours worked by employee 2.
hours[1] = int(input("Enter the hours worked by employee 2: "))
#Get the hours worked by employee 3.
hours[2] = int(input("Enter the hours worked by employee 3: "))
#Display the values entered.
print("The hours you entered are:")
print(hours[0])
print(hours[1])
print(hours[2])
Sie setzen keine Größe mit 'hours = [SIZE]', Ihre Liste hat nur einen Index – PRMoureu
'[SIZE]' ist eine Liste mit 1 Elementen, deren einziges Element die Zahl 3 ist. – user2357112