Reputation: 63
def guessingTime(answer, username):
vdfile = open("victorydefeat.txt", "a")
now = time.asctime(time.localtime(time.time()))
victory = username + "successfully guess" + answer + "on" + now
defeat = username + "was unable to guess" + answer + "on" + now
print("That's 20! Time to guess.")
guess = input("Is it a(n): ")
if guess.lower() == answer:
print("You got it! Congratulations!")
vdfile.write(victory)
vdfile.write("\n")
else:
print("Sorry, but the answer was", answer)
vdfile.write(now)
vdfile.write("\n")
vdfile.close()
def main():
print("Welcome to 20 questions! The game where I (your humble program) will think of an object and you (the beloved user) will try to guess it!")
username = print(input(("Now, before we begin, I'd like to know your name (for recording purposes): ")))
infile1, infile2, answer = getAnswer()
#startAsking(infile1, infile2)
guessingTime(answer, username)
main()
The error message is "unsupported operand type(s) for += 'NoneType' and 'str'" for the "victory =" line. I want to write: " successfully guessed on ". What do I do?
Upvotes: 1
Views: 44
Reputation: 122061
You can just use time.asctime()
, it is the local time by default. Also, string formatting is your friend:
"{0} guessed {1} on {2}".format(username, answer, time.asctime())
However one of your arguments username
or answer
is None
(as unholysampler explains) which is why you get that specific error.
Upvotes: 0
Reputation: 17331
print()
does not return a value. Because of this username
is being set to None
.
input()
will print the string it is passed and return the entered text. You just want the following:
username = input("Now, before we begin, I'd like to know your name (for recording purposes): ")
Upvotes: 1