I'm currently trying to make a simple code (basically mad-libs) and I made a variable called time
. The user is supposed to type in something like months or days. If a user inputs month or day, an if
statement is supposed to add an "s"
to make it plural:
time = str(input("Pick a measurement of time (ex. days): "))
if time[len(time)] != "s":
time = time + "s"
When I test this code out, it gives me this error:
Traceback (most recent call last):
File "D:/nikis_staff/PROGRAMMING/madlibs.py", line 51, in <module>
if time[len(time)] != "s":
IndexError: string index out of range
I know that string index out of range
means the string is longer than I thought it was but I am using len()
.