Skip to content
← Back to Community
Why is repl broken?
Profile icon
ChezCoder

Why isn't my if statement in a while loop working?
https://repl.it/@ChezCoder/Python-Text-Editor

from os import system,name from termcolor import cprint from time import sleep fileName = 'filedat.txt' readFile = open(fileName) writeFile = open(fileName,'w').write(str(readFile.readlines())) def clear(): if name == 'nt': system('cls') else: system('clear') def promptEditOptions(): fileOption = 0 clear() print('1: Add a Line') print('2: Edit a Line') print('3: Clear a Line') print('---------------') print('4: Wipe file\n') fileOption = input('> ') return fileOption while True: if promptEditOptions() == '1': fileOption = 1 elif promptEditOptions() == '2': fileOption = 2 elif promptEditOptions() == '3': fileOption = 3 elif promptEditOptions() == '4': fileOption = 4 print(fileOption) sleep(1)
Voters
Profile icon
StealthHydra179
Profile icon
ChezCoder
Comments
hotnewtop
Profile icon
AllAwesome497

One post was sufficient. You only need to post once, posting multiple times will not help you get an answer. Don't spam posts.

Profile icon
ChezCoder

@AllAwesome497 I didn't mean to. I tried to post but then it didn't load so then I tried posting another one which worked but it turned out the first post finally processed and I couldn't delete them because it kept logging me out when I tried to so... srry anyways.

Profile icon
AllAwesome497

@ChezCoder it's fine.

Profile icon
Zavexeon

The variable fileoption is out of scope for the loop, meaning that it can't access it. Try moving the declaration out of the promptEditOptions() function.