Mohibur Rashid
У вас много чего не так с вашим кодом. Я просто упомяну и объясню эти вопросы
print("Welcome to randomprogram.....to enter please provide Username and Password")
def main():
a = open('C:/Users/josep/Documents/randomprogram(acc).txt','r')
# 1. readlines read all the lines and return. And `a` object's offset set to last.
# 2. readlines work with no parameter too. In case of no parameter it will return all the items. if you put number it will start reading from the number you have put. and indexing starts from 0. a.readlines(1) will read from second line, skipping first line.
b = a.readlines(1)
# if you want to do readlines operation second time you need to set the offset back to start. Read the document http://python-reference.readthedocs.io/en/latest/docs/file/seek.html about this
c = a.readlines(2)
c = [a.strip() for a in c] # why did you use a? you are already using a for file handling. Try other variable name. and for your information both b and a are array
print(c)
d = input("Username:") #i type user
e = input("Password:") #i type 123
f = (d + e)
print(f)
if f == c: # c is array, should be handled as array
# from your coding style i am guessing. line 1 contains the program name and second line contains username and password. and you tried to read that one in variable b.
g = a.readlines(1)
g = [a.strip() for a in g]
print("Welcome to randomprogram" + f)
else:
print("Wrong Username and/or Password.....try again")
main()
main()
Мое предложение будет читать все строки, как это делается, и помещать все строки в соответствующие переменные; пример:
a=open(fname,'r')
(programName, userpassword)=[f.strip() for f in a.readlines()]
print(programName);
print(userpassword);
*
seek — Python Reference (The Right Way) 0.1 документация[
^]