Skip to content

Instantly share code, notes, and snippets.

@andrelashley
Created February 21, 2012 18:56
Show Gist options
  • Save andrelashley/1878132 to your computer and use it in GitHub Desktop.
Save andrelashley/1878132 to your computer and use it in GitHub Desktop.
Get user's information, display it and log it to a text file
# Author: Andre Lashley
# Date: February 21, 2012
# Description: Get user's information, display it and log it to a text file
def display_user_info():
# get the users name
name = raw_input("Hello there, what's your name? ")
# get the users age
print "Thanks " + name + "!"
age = raw_input("How old are you? ")
# get the users reddit user name
reddit_name = raw_input("What is your reddit username? ")
# display the information back to the user
user_data = "your name is %s, you are %s years old, and your reddit username is %s" % (name, age, reddit_name)
# log the users information to a file
filename = "log.txt"
# create a file object in write mode
f = open(filename, "w")
# write the user's information to the file
f.write(user_data)
# close the file
f.close()
# return the user's info so we can print it out
return user_data
my_info = display_user_info()
print my_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment