Tuesday 15 March 2011

python - when i run the program nothing happens -



python - when i run the program nothing happens -

def file(): username_file = open("username_file.txt", "r") username_file.close() username_file = open ("username_file.txt", "a") firstname = input("firstname:") lastname = input("lastname:") fullname = (firstname + lastname) username_file.write(str(fullname)) username_file.close()

when seek run programme nil happens, know why?

your programme working perfectly. defines function file() , exits.

if want call function, think putting next line @ bottom:

file()

by way of example, programme may appear not much:

def print42(): print 42

but this 1 calls function useful work:

def print42(): print 42 print42()

so, if just:

add file() line bottom of file, starting in first column; make sure you're using python3 (or alter input raw_input python2); and actually have username_file.txt file beforehand, avoid exception while opening read;

then work fine (though names hard against each other, paxdiablo rather pax diablo).

python

No comments:

Post a Comment