0
x = input(Fore.YELLOW + "What specific account would you like to print? (Input 0 for line 1)\n" + Fore.RED)
c = accountlines[105].split("`") # Change [0] to whichever line number (minus 1) that you would like to print, so for line 10, put [9].
email = c[1]
password = c[3]
print(Fore.BLUE + f"----------------------------------------------------------\n{email}:{password}\n----------------------------------------------------------" + Fore.WHITE)

I'm trying to have an input which would represent an element number. So, if you would like to call the 106th element in the array, you would put 105 when it asks for an input. This would lead x to equal 105, so I would like to replace the [105] in c with [x], but the brackets ask for an integer, and returns the following error when you use a variable instead:

Traceback (most recent call last):
  File "account.py", line 30, in <module>
    print(all_lines[x])
TypeError: list indices must be integers or slices, not str

Is it possible to use a variable in place of this integer? What would I need to do to accomplish this? Thanks :)

TTV jokzyz
  • 349
  • 1
  • 3
  • 13

1 Answers1

0

As @chepner suggested, your input is of type string ("105" vs 105). You need to convert the string to integer, as such, change:

x = input(Fore.YELLOW + "What specific account would you like to print? (Input 0 for line 1)\n" + Fore.RED)

to:

x = int(input(Fore.YELLOW + "What specific account would you like to print? (Input 0 for line 1)\n" + Fore.RED))

If your users find the whole countstart from 0 confusing you could improve the above, so they can enter 106 for what they see as account 106:

x = int(input(Fore.YELLOW + "What specific account would you like to print?)\n" + Fore.RED))-1
0buz
  • 3,443
  • 2
  • 8
  • 29