Created
March 3, 2017 22:26
-
-
Save joetechem/f120b5ea06c7d43a38506f6f7717682f to your computer and use it in GitHub Desktop.
review of user input and intro to while loops
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
# Let's get some input from the user. | |
name = raw_input('Please enter your name: ') | |
# How can we do something with the value that was entered? | |
# In other words, how can we display the user's name??? | |
# one way, is a print statement with some concatenation (or adding strings and variables nad other characters) | |
print("Hello " + name + "!") | |
#### | |
#### | |
# make a new python file called: | |
# games_list.py | |
# What if you wanted to store a list of your favorite games and have other people add to that list with theirs? | |
# Start with a list containing several names. | |
games = ['tetris', 'pong', 'red rover'] | |
print("\nHere is a list of my favorite games") | |
# Ask the user for a game. | |
new_game = raw_input("Please tell me your favorite game: ") | |
# Add the new game to our list. | |
games.append(new_game) | |
# Show that the game has been added to the list. | |
print(games) | |
# This works great, but the program ends before we can have someone else add to the list. | |
### | |
### | |
# adding a while loop to have the program continue until something happens | |
print("\nHere is a list of my favorite games") | |
games = [ | |
'tetris', | |
'pong', | |
'red rover'] | |
print(games) | |
new_game = "" | |
while new_game != 'quit': | |
new_game = raw_input("So I can add it to our list, please tell me your favorite game: ") | |
# games.append(new_game) # Comment this line, so 'quit' is not added to the list | |
print(games) | |
if new_game != 'quit': | |
games.append(new_game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment