Skip to content

Instantly share code, notes, and snippets.

Created March 27, 2014 21:58
Show Gist options
  • Save anonymous/9819953 to your computer and use it in GitHub Desktop.
Save anonymous/9819953 to your computer and use it in GitHub Desktop.
mylist032614
import socket # imports the socket module
import sys # imports the sys module
import console # imports the console module
usr = raw_input('What is your name? \n').title() # asks for users name for the hostname information
sname = socket.gethostname() # sets sname to gethostname
print '\nThis program is being run by', usr, 'on machine name', sname # displays host information
mylist = ['Red', 'White', 'Blue', 'Yellow', 'Green', 'Orange'] # sets mylist to colors
templist = list(mylist) # sets templist as mylist
runagain = 'y' # sets runagain to a y values
while runagain == 'y': # for looping
print '\nThe current colors are:', templist # print out list so user knows what colors are already there
clradd = raw_input('\nWould you like to add any colors to the list? y or n\n')
while clradd == 'y':
colors = raw_input('\nWhat colors would you like to add to the list? Please type one color. \n').title()
templist.append(colors) # appends color to the list
print templist # prints out new list
print '\nAscending and Descending' # print out ascending and descending lists
print '-' * 30
print '\nAscending (high to low): ', sorted(templist, reverse=True)
print '\nDescending (low to high): ', sorted(templist, reverse=False)
clrdel = raw_input('\nWould you like to remove any colors from the list? y or n\n')
while clradd == 'n':
clrdel = raw_input('\nWould you like to remove any colors from the list? y or n\n')
while clrdel == 'y':
try:
removecolor = raw_input('\nWhat colors would you like to remove? ').title() # asks user color to remove
templist.remove(removecolor) # removes color from the list
except ValueError:
print 'Looks like that color was not in the list, try again.'
continue
print 'Updated list\n', templist # prints out updated list
runagain = raw_input('\nWould you like to run this program again again? y or n')
if runagain == 'n': # if runagain is n
console.hide_output() # hide the output
while clrdel == 'n':
runagain = raw_input('\nWould you like to run this program again again? y or n') # asks user to run again
if runagain == 'n': # if runagain is n
console.hide_output() # hide the output
sys.exit() # stops the program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment