Browse Source

lists

master
Ken Schaefer 9 months ago
parent
commit
699ebb523c
  1. 9
      day-04/lists_example.py
  2. 15
      day-04/pirate_treasure.py
  3. 7
      day-04/random_name.py

9
day-04/lists_example.py

@ -1,2 +1,9 @@
states = ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut", "Massachusetts", "Maryland", "South Carolina", "New Hampshire", "Virginia", "New York", "North Corolina", "Rhode Island"]
states = ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut",
"Massachusetts", "Maryland", "South Carolina", "New Hampshire",
"Virginia", "New York", "North Corolina", "Rhode Island"]
print(states[0])
print(states[-1])
list.append("Illinois")
list.extend("Tennessee, Kentucky")

15
day-04/pirate_treasure.py

@ -0,0 +1,15 @@
import string
line1 = [" ", " ", " "]
line2 = [" ", " ", " "]
line3 = [" ", " ", " "]
map = [line1, line2, line3]
print("Hiding your treasure! X marks the spot.")
position = input() # Where do you want to put your treasure
col = position[0]
row = position[1]
map[string.ascii_lowercase.index(col)][int(row)-1] = 'X'
print(f"{line1}\n{line2}\n{line3}")

7
day-04/random_name.py

@ -0,0 +1,7 @@
import random
names_string = "Angela, Ben, Jerry, Michael, Chloe"
names = names_string.split(", ")
random_name = random.randint(1, len(names)-1)
print(names[random_name])
Loading…
Cancel
Save