Python: Code in IDE is correct, but is incorrect in homework

So I am working on Python homework, and I prefer to write the answers to the homework in an IDE, then copy and paste my answer. For this specific problem I did just that, and while the code works in the IDE just fine, it is marked as incorrect on the homework.

Homework question: Write a loop that reads strings from standard input, where the string is either "duck" or "goose". The loop terminates when "goose" is read in. After the loop, your code should print out the number of "duck" strings that were read.

What my homework says: Problems Detected: ⇒ The value of _stdout is incorrect.

My answer:

duckcount = 0
animal = ''
while True:
    animal = input('enter animal')
    if animal == 'duck':
        duckcount +=1
    elif animal == 'goose':

The code works fine in my IDE, but the error message I get on my homework is: The value of _stdout is incorrect.

I am wondering if your teacher added their own spaces to the input due to your input string not having any by default.

Try this:

duckcount = 0
animal = ''
while True:
    animal = input('enter animal: ').strip()
    if animal == 'duck':
        duckcount += 1
    elif animal == 'goose':

if duckcount == 1:
    print('There is {} duck!'.format(duckcount))
    print('There are {} ducks!'.format(duckcount))


enter animal: duck   
enter animal:    duck
enter animal:  duck
enter animal: goose
There are 3 ducks!

Python 3.2 how to set correct and incorrect answer on questions inside 2 lists to map questions to correct\incorrect then doing a lookup on that. n Correct We

OK I figured it out, user10987432 gave me this idea. All i did was replace 'enter animal' with ''. I guess I was supposed to just use a blank space for an input. (Which works but I like having a little message on what to do as a preference). thanks for all the responses!

Python is an easy-to-use but powerful programming language that is particularly well-suited to quickly creating small programs. IDLE is more than just an editor; it is a simple but powerful IDE, or "integrated development environment", which lets you edit, run, navigate, and debug Python code.

_stdout is the output that your program is writing to when it prints things on the command line. The logic of your program is perfetly fine as it is.

Since the output is marked as being incorrect I would first ask the teacher if he wants a specific wording. I expect that he/she probably hardcoded a specific output into the Homework-Parser. If that's the case then just change your print(duckcounter) to whatever sentence/output the teacher hardcoded (as I said the best was would be to ask him/her if she/he has done that).

As said by Mike - SMT the teacher could have modified the input statement as well. You can think about the input as a two-part command. First it prints something out to _stdout (output on the command line) and then waits for a specific action (usually that you type something in and hit enter).

You could as well do something like this:

animal = ''
counter = 0
while animal != 'goose':
  animal = input('Please enter either "Goose" or "Duck": ')
  animal = animal.lower() # make everything lowercase
  if animal == 'duck':
    counter += 1
print('You have typed "duck" {} times'.format(counter))

If you have any questions let me know.

Answer in Python, show all code: Implement the following program for playing the game of heads/tails. The rules of the game are as follows: The computer will ask the player to call heads or tails.

%) Enter three correct assertEqual tests for the function described below Answer: penalty regime: 0,0 - 59 Check Below is a Python function definition for a linear search of a list ist for element. It returns the index at which element can be found in the list for Nonel if element is not in the list det linearsearch(lot, element) 1 let ites

Introduction: This handout introduces Python programming in the Eclipse Integrated Development Environment (IDE). It is presented partly as a tutorial and partly in a "cook book" style: read the text and follow the instructions to gain some hands-on experience operating this software, which we will use extensively when we write, test, and debug our own programs.

To check your code, you must copy and paste, drag and drop a Python file or directly type in the Online Python editor below, and click on "Check Python syntax" button. You can see the user guide to help you to use this python checker tool.

  • Not sure. This appears to work for me. I write duck 3 times then goose and I get the result 3.
  • print automatically suffixes the output string with a newline (\n). Maybe the homework parser is doing a string comparison and failing it because it shouldn't end in a newline? You could trying doing print(duckcount, end='') to remove the newline and see if it likes that any better.
  • I'm guessing you're using some kind of grading script to evaluate your homework. In my experience those tend to be very picky - if the output that your code generates doesn't exactly match what it is programmed to recognize as correct, it flags your submission as incorrect. A stray whitespace, a character which should be upper- or lowercase, a missing prompt, an "incorrectly" worded prompt or even an excessive prompt which it didn't expect to see - these are all possible causes. For example, did your teacher explicitly say "make it print 'enter animal' for each iteration"?