Python Forum
It worked now it doesnt...ugh
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
It worked now it doesnt...ugh
#11
i get
Error:
print('FAQ deleted') ^ IndentationError: unexpected indent
from the code above

The indenting in this part needs fixing
        if item in FAQ:
            del(FAQ[item])
                print('FAQ deleted')
            else:
                print("That question is not in the dictionary! ")
Reply
#12
(Aug-07-2019, 07:25 PM)Yoriz Wrote: i get
Error:
print('FAQ deleted') ^ IndentationError: unexpected indent
from the code above

yes I fixed that. just now.
now it runs but does not return with FAQ already exists
Reply
#13
I fixed the indentation and now get stuck in option 1 as option is not altered inside of the while loop.
Output:
1: Add a Question 2: Delete a Question 3: List all FAQ 4: Exit Please enter your selection: 1 Enter a question to be added: this The answer to the question is: that Your FAQ has been added. Enter a question to be added:
But it if i enter the same question
Output:
Enter a question to be added: this The answer to the question is: that FAQ already exists Your FAQ has been added. Enter a question to be added:
it does report "Your FAQ has been added." after answer has been added, as the if statement is after both the question and answer input.
Reply
#14
(Aug-07-2019, 07:34 PM)Yoriz Wrote: I fixed the indentation and now get stuck in option 1 as option is not altered inside of the while loop.
Output:
1: Add a Question 2: Delete a Question 3: List all FAQ 4: Exit Please enter your selection: 1 Enter a question to be added: this The answer to the question is: that Your FAQ has been added. Enter a question to be added:

I moved the option = int(input()


while not done:

    print(menu)
    option = int(input("Please enter your selection: "))

    if option == 1:
        question = input("\nEnter a question to be added: ")
        answer = input("\nThe answer to the question is: ")
        if question in FAQ:
            print('FAQ already exists')
        FAQ[question] = answer
        print('Your FAQ has been added. ')
        item = question
Reply
#15
Move the if to immediately after the question input, then it will report 'FAQ already exists' without first waiting for the answer input
Reply
#16
(Aug-07-2019, 07:41 PM)Yoriz Wrote: Move the if to immediately after the question input, then it will report 'FAQ already exists' without first waiting for the answer input

that worked thank you very much

it worked with the exception of this below:

Please enter your selection: 1

Enter a question to be added: what
FAQ already exists!
Please rephrase your entry!

The answer to the question is:
it does not go back to the asking what FAQ you want to add
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  im not sure what ive done wrong code doesnt run dgizzly 3 1,357 Nov-16-2022, 03:02 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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