Slow Poke Slow Poke - 2 months ago 13
Python Question

Issue with int/input/print in homework

This is a three part question that I am having issues with....


  1. My output is not giving me the option to input my integer, it is printing "none" on the following line and skipping the option

  2. Ending the file trigger is not working properly

  3. counting the players that I have recorded data for....I honestly don't know where to start on counting inputs



--------------------My Output----------------------
You will be asked to enter players names and scores
When you have no more names, enter End

Enter Player's Name or End to exit program: Randy
Enter Randy 's golf score:
None
------------------My Output END--------------------

My code;



def main():
#introduction to user explaining required information to be entered
print("You will be asked to enter players names and scores")
print("When you have no more names, enter End")

#double blank space
print("\n")

#defined y/n
anotherPlayer = "y"

#define file path to save user input
usersFile = open('golf.txt', 'w')

#
while anotherPlayer == "y":
playerName = input("Enter Player's Name or End to exit program: ")
score = int(input(print("Enter", playerName, "'s golf score: ")))
usersFile.write(playerName + "," + str(score) + "\n")

anotherPlayer = input("Is there another player? y / End: ")

End = usersFile.close()

main()


-----------------end my code--------------------

I need it to say;

---------Assignment output Needed-----------------

You will be asked to enter players names and scores
When you have no more names, enter End

Enter Player's Name or End to exit program: Randy
Enter Randy 's golf score: 50

Enter Player's Name or End to exit program: End
You have written 1 players records to golf.txt

---------End assignment output----------------

Answer

Try this:

def main():
    # introduction to user explaining required information to be entered
    print("You will be asked to enter players names and scores")
    print("When you have no more names, enter End")

    # double blank space
    print("\n")

    # defined y/n
    anotherPlayer = "y"

    # define file path to save user input
    usersFile = open('golf.txt', 'w')

    #
    while anotherPlayer == "y":
        playerName = raw_input("Enter Player's Name or End to exit program: ")
        score=input("Enter "+ str(playerName)+"'s golf score: ")
        usersFile.write(playerName + "," + str(score) + "\n")

        anotherPlayer = raw_input("Is there another player? y / End: ")

    End = usersFile.close()


main()