Aug-17-2018, 10:56 PM
Hello,
I just started learning to code and I was doing my homework, I ran into an error.
The error is saying this:
Traceback (most recent call last):
File "/Users/daphne/Desktop/School Stuff/Computer science/IntroProg/Project/test3.py", line 8, in <module>
if nom[i] == char:
IndexError: string index out of range
I know it is related to my "nom[i]", but I don't know how to fix. If anyone could help me out, I would really appreciate!
Here is my code:
I just started learning to code and I was doing my homework, I ran into an error.
The error is saying this:
Traceback (most recent call last):
File "/Users/daphne/Desktop/School Stuff/Computer science/IntroProg/Project/test3.py", line 8, in <module>
if nom[i] == char:
IndexError: string index out of range
I know it is related to my "nom[i]", but I don't know how to fix. If anyone could help me out, I would really appreciate!
Here is my code:
nom = input('Enter a name:') length = len(nom) i = 0 nb_e = 0 char = 'e' while i <= length: if nom[i] == char: nb_e = nb_e + 1 i = i + 1 print('Theres', nb_e, 'e')