Comments

You must log in or register to comment.

Twoeyes wrote (edited )

I would have approached it slightly different.

Something like (just an example, syntax is wrong)

X = 0
Do
pyautogui.password("are you a moose?")
If answer = true then
X = 1
Else
pyautogui.alert("wrong try, again")
End if
Loop until X = 1

Repeat for each question

You could also do stuff with an array or some lists to contain it all in the one loop, but I don't know the syntax well enough to write it off the top of my head.

4

nulloperation wrote (edited )

You could also do stuff with an array or some lists to contain it all in the one loop, but I don't know the syntax well enough to write it off the top of my head.

Here's my attempt at that. If you want to add more questions, just add them to the questions list.

questions=[
        {"q":"famous blue anti-civ hedgehog?","a":"sonic"},
        {"q":"blue men who live in mushrooms?","a":"smurfs"}
]

def ask(question):
    print(question["q"])
    return input().lower() == question["a"].lower()

def ask_all(questions):
    if questions:
        if ask(questions[0]):
            return ask_all(questions[1:])
        else:
            return False
    else:
        return True


if ask_all(questions):
    print('succes')
else:
    print('fail')

@kokoaitu You should really use code blocks for pasting code, especially a language like Python with whitespace sensitive syntax. Also, I think your do ... until construct is not really quite Python.

@raddleboy If you're new to Python or programming in general, I'd suggest sticking with plain Python (without GUI libraries) while you're getting to know the language. Using time.sleep() in the same thread as the GUI can be problematic as it can lock up the GUI.

Extra points if anyone can do this

3

nulloperation wrote

Can't quite make out what you're asking. Are you trying to make a puzzle / quiz program, or are you trying automate a task that for some reason requires manual input?

3

raddleboy OP wrote (edited )

Its a puzzle program that requires manual input riddle

Example:

Alert Box

What is hot, wet, long and short and burns if you drown it?

Here the person needs to type the correct answer in. If the answer is correct, he gets the next puzzle. If the answer is wrong the program shuts down instead of giving him multiple opportunities to him.

<div>
pyautogui.hotkey('win')
time.sleep(3)
pyautogui.write('google chrome')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(5)
pyautogui.alert("an_alert")
pyautogui.alert("another_alert")
pyautogui.alert("yet_another_alert")
cont = pyautogui.prompt(text="yes or no", title="title?")
if cont == "yes":
    password = pyautogui.password("The_riddle_in_question", "the_title")
    if password  == "the_answer":
        password = pyautogui.password("The_riddle_in_question", "the_title")
        if password  == "the_answer":
                password = pyautogui.password("The_riddle_in_question", "the_title")
                if password == "the_answer":
                    pyautogui.alert('another_alert', "title")
                    time.sleep(1)
                    pyautogui.hotkey('ctrl', 'l')
                    time.sleep(.5)
                    pyautogui.write('www.some_website.com')
                    time.sleep(.5)
                    pyautogui.hotkey('enter')
                else:
                    pyautogui.alert("Wrong Answer")
        else:
            pyautogui.alert("Wrong Answer")
    else:
        pyautogui.alert("Wrong Answer")
else:
    pyautogui.alert("raddleboy")
</div>

What is the solution?

4

nulloperation wrote

What is the solution?

Are you asking what the solution is to the puzzle you posted? It appears to just be "the_answer" in your code above. Or, are you asking how to implement it properly? In that case, I'd probably just use a list of question-answer pairs rather than nested if-statements. The nested if-statements get one level deeper for each question.

If you need a GUI for your quiz app, Tkinter is built-in in Python. Pyautogui is for automating GUI interactions, not for creating GUIs.

3