Describe the bug
The input function does not perform as the Python documentation states that it should. This means that program behavior is different when run in Python 3 on an end user's computer and when it is submitted via Submitty. This has caused a lot of problems for students in CS I. Moreover, from talking to students who took CS I last semester, it seems like this behavior is new, which indicates a potential issue with testing.
Expected behavior
Consider the following code:
s = input("Enter something here: ")
print("You entered:", s)
The program will behave like this:
Enter something here: Monty Python's Flying Circus
You entered: Monty Python's Flying Circus
Submitty should behave in the same manner. When simulating user input that says Monty Python's Flying Circus, the output should be identical to the above (running locally).
To Reproduce
Submit the above program via Submitty. Have Submitty simulate user input that says Monty Python's Flying Circus. The "output" will be as follows:
Enter something here: You entered: Monty Python's Flying Circus
There are two issues with this:
- The Python documentation states that input "...reads a line from input, converts it to a string (stripping a trailing newline), and returns that." Notice the trailing line at the end of the output? This is because Submitty includes an extra newline at the end of the input string. This is not expected behavior and is inconsistent with local Python installations.
- The user's input is not echoed back. On end user systems, any text typed in the terminal is echoed back to the user, including the newline. While Python will not echo anything back when a stream is piped into it, CS I students especially will find this behavior confusing as something that looks fine on their own computer will produce a different output on Submitty.
A workaround is as follows:
def submitty_input(query):
s = input(query)
print(s) # Simulate an echo
return s[0:-1] # Trim the trailing newline
You can use normal input on your local system and switch to submitty_input before uploading and it will work as on your computer.
Configuration
- OS:
Linux 5.8.0-43-generic #49~20.04.1-Ubuntu SMP Fri Feb 5 09:57:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
- Python version:
Python 3.8.10
- Browser: N/A
Describe the bug
The input function does not perform as the Python documentation states that it should. This means that program behavior is different when run in Python 3 on an end user's computer and when it is submitted via Submitty. This has caused a lot of problems for students in CS I. Moreover, from talking to students who took CS I last semester, it seems like this behavior is new, which indicates a potential issue with testing.
Expected behavior
Consider the following code:
The program will behave like this:
Submitty should behave in the same manner. When simulating user input that says
Monty Python's Flying Circus, the output should be identical to the above (running locally).To Reproduce
Submit the above program via Submitty. Have Submitty simulate user input that says
Monty Python's Flying Circus. The "output" will be as follows:There are two issues with this:
A workaround is as follows:
You can use normal
inputon your local system and switch tosubmitty_inputbefore uploading and it will work as on your computer.Configuration
Linux 5.8.0-43-generic #49~20.04.1-Ubuntu SMP Fri Feb 5 09:57:56 UTC 2021 x86_64 x86_64 x86_64 GNU/LinuxPython 3.8.10