A
A
amoor2016-08-24 22:01:34
Python
amoor, 2016-08-24 22:01:34

How to beautifully display the result of the code?

Hello. There is a code that receives the data entered by the user and writes it to a file, but it happens that it will display only the login or only the password, and it outputs them like this: "y,u,i,o,p,". I would like to get a result that looks like this:
Login: tyuir
Password: 1234567
Please help me.
Here is the code itself:

login = input('Логин: ')
password = input('Пароль: ')

li = [login, password]

f = open('text.txt', 'w')
for index in login and password:
  f.write(index + ",")
print(li)

f.close()

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Solomennikov, 2016-08-24
@spidespidepide

This is elementary, you access the desired element of the list using indexing.
In a file by means of a cycle you wrote down indexes! You can also do without the loop by converting the list to a string.
Also, keep in mind that the file you have will be overwritten each time, and not changed by additions.

login = input('Логин: ')
password = input('Пароль: ')

li = [login, password]

f = open('text.txt', 'w')
f.write(str(li))
print("Login: {} Password: {}".format(li[0], li[1]))
f.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question