Here is my code...
from datetime import datetime def userLogin() : Name = input("Please type your Username ") if Name == "User1" : print ("Welcome User1! " + timeIs()) if Name == "User2" : print ("Welcome User2! The time is " + datetime.strftime(datetime.now(), '%H:%M')) if Name == "User3" : print ("Welcome User3! The time is " + datetime.strftime(datetime.now(), '%H:%M')) def timeIs() : print ("The time is " + datetime.strftime(datetime.now(), '%H:%M')) print (userLogin())
As you can see, for User2 and User3 I have set out the full operation for getting the time via the datetime module. In the User1 statement however I have tried to shorten it down by defining a second statement (timeIs) and using that to state the time. Every time I 'log in' user1, python says this-
Please type your Username> User1 The time is 19:09 Traceback (most recent call last): File "/home/pi/Documents/User.py", line 15, in <module> print (userLogin()) File "/home/pi/Documents/User.py", line 6, in userLogin print ("Welcome User1! " + timeIs()) TypeError: Can't convert 'NoneType' object to str implicity
Cheers, Carl