Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created August 10, 2012 19:04
Show Gist options
  • Save benhosmer/3316937 to your computer and use it in GitHub Desktop.
Save benhosmer/3316937 to your computer and use it in GitHub Desktop.
Introduction to Python - Applying variables, user input, and lists with the list.append
# A simple friend game score keeper
# This is used to demonstrate variables, user input, and using lists to
# track values. It is meant as a starting point.
username = raw_input("Enter your name: ")
userage = raw_input("Enter your age: ")
friendsname = raw_input("Enter your friends's name: ")
friendsage = raw_input("Enter your friend's age: ")
print "Hello " + username + ", you are " + userage + " years old.\n"
print "Your friend, " + friendsname + ", is " + friendsage + " years old.\n"
userscore = []
friendscore = []
user_entered_score = input("Enter an integer for your score: ")
friend_entered_score = input("Enter an integer for friend's score: ")
userscore.append(user_entered_score)
friendscore.append(friend_entered_score)
totalscores = userscore[0] + friendscore[0]
print "You scored " + str(userscore[0])
print "Your friend, " + friendsname + ", scored " + str(friendscore[0])
print "Your combined scores are " + str(totalscores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment