Python Forum
Problem with readlines() and comparisons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with readlines() and comparisons
#1
I want to write a program that reads the passwords from a file and compares them with a user input. The comparisons don't seem to work, though. The if-conditions are also called unequal ("ungleich") if this is not the case.

gefragt = input("Zu testendes Passwort: ")

sicher = 1

textdatei = open("passwoerter.txt","r")
passwoerter = textdatei.readlines()

for test in passwoerter:
    if test == gefragt:
        sicher = 0
        print (f"{gefragt} gleich {test}")
    else:
        print (f"{gefragt} ungleich {test}")
        
if sicher == 0:
    print("Unsicher")
else:
    print ("Sicher")
Output (input=password):
Zu testendes Passwort: password
password ungleich 123456
password ungleich password
password ungleich 12345678
password ungleich qwerty
password ungleich 123456789
Sicher
Reply


Messages In This Thread
Problem with readlines() and comparisons - by dudewhoneedshelp - Jul-23-2020, 09:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Using readlines to read data file and sum columns Laplace12 4 3,657 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Comparisons with functions menator01 1 1,871 Jun-07-2020, 09:28 AM
Last Post: Gribouillis
  [Python3] Trailing newline in readlines. LWFlouisa 4 4,934 Mar-10-2020, 09:57 AM
Last Post: perfringo
  Problem with readlines() assignment Sunioj 5 4,846 Oct-27-2019, 06:20 AM
Last Post: perfringo
  List Comparisons and Deleting Valuebles KaleBosRatjes 4 3,775 May-13-2018, 02:14 PM
Last Post: volcano63
  readline() and readlines() rpaskudniak 9 30,215 Nov-21-2017, 07:39 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020