Created
August 10, 2012 19:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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