Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input() and print() out of sync in Activecode #475

Open
tc-kirby opened this issue Mar 28, 2024 · 2 comments
Open

input() and print() out of sync in Activecode #475

tc-kirby opened this issue Mar 28, 2024 · 2 comments

Comments

@tc-kirby
Copy link

Please check the current issues Many bug reports are duplicates, this just creates more work for us. Searching the issues first may give you your answer or a workaround! If not adding new information to an existing report is much more helpful than a new report.

What Course are you in
The course I'm an instructor for - tky_y10_bluebook

What Page were you on
https://runestone.academy/runestone/admin/assignments?selected_assignment=177800
...with the following code:

What is your username

Describe the bug
If I write the following program, the print() and input() directives are out of sync:

import random
attempts = 0
guess = None
number = random.randint(1,100)

while(guess != number):
    guess = int(input("Guess the number:"))
    if guess > number:
        print("You guessed too high. Try again.")
    elif guess < number:
        print("You guessed too low. Try again.")
    attempts = attempts + 1

print(f"Correct! You guessed the number {number} in {attempts} guesses.")

Javascript Errors
Sorry, my work have blocked access to devtools in Edge :-(

@bnmnetp
Copy link
Member

bnmnetp commented Mar 28, 2024

Ahh, the joys of async programming in Javascript.... Especially when you insert prompt.

I can make it behave by adding a time.sleep(0.1) at the bottom of the loop.

A better more permanent fix is going to take some more investigation... maybe replacing the use of an prompt for getting input.

Funny that this has not shown up before...

@bnmnetp
Copy link
Member

bnmnetp commented Mar 28, 2024

Note to self:

Look at outputfun in activecode.js -- maybe we can wrap prompt in a promiseToSuspension to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants