[Solved] I’m trying to make a quiz on Python but my code keeps repeating


Alright, so first of all we need to improve the program layout , maybe call in some functions would be useful. Here is some tips to fix the program.

First of all use : if username.strip() and password.strip() in line: [Use the .strip() function so it will match a word.

Your program is inefficient because if you press another value as in 2 it will break the program. You want to loop it and loop it over and over again therefore use the while True statement and create a function.

Add a function called exampleFunction() (I.E) and then on the bottom of the code ad this line but obviously indent it.

while True:

     exampleFunction()

You don’t need to use a or r just do file=open(“your file.txt”)

For example,

genre=input("What is the film  you would like to search?: ")
f=open("Films.txt")
for line in f:
    if genre in line.strip():
        print(line)

I would personally fix this myself and post a copy of the code however this is too minor to fix therefore i’m leaving it to you.

Goodluck,

Matin

2

solved I’m trying to make a quiz on Python but my code keeps repeating