jeudi 26 novembre 2020

Username, ID, Password, can't identify what's wrong

I wanted to make a "log-in" system, so you make a username, through Input then give the username an ID (between 1 and x). The username and ID will be stored in document: "tomtdokument.txt" (it's norwegian)

My idea forward would be to then maybe put the ID into another document with a password, which will also be chosen by Input. However, haven't gotten close to that step yet. That´s my general idea, but I'm having a hard time adding the username to the ID.

I'm not sure what do to, because I'm not sure what the problem is, there's no Error code. So there's no problem with the code, but it won't do its purpose, and it won't write the username in the file.

Anyway, my code is below, and the problem I would assume is in the while-loop, probably in the if-statement:

import random

username = str(input("Username please: "))
ran = random.randint(1, 10)
ran = str(ran)
print(ran)

f = open("tomtdokument.txt", "w")

start_number = 1
amount_lines = 10

while amount_lines >= start_number:
    z = str(start_number) + "\n"
    f.write(z)
    if start_number == ran:
        f.write(ran + username)
    start_number += 1

f.close()

Aucun commentaire:

Enregistrer un commentaire