inventory = ["sword","armor","shield","heading potion"]
print("Your items:")
for item in inventory:
print(item)
print(len(inventory))
if "sword"in inventory:
print("Okay!")
print(inventory[1])
print(inventory[0:2])
chest = ["lzq","lfp"]
inventory += chest
print(inventory)
inventory[5] = "dqq"
inventory[0:2] = ["future"]
del inventory[0]
del inventory[0:2]
print(inventory)
Your items:
sword
armor
shield
heading potion
4
Okay!
armor
['sword', 'armor']
['sword', 'armor', 'shield', 'heading potion', 'lzq', 'lfp']
['lzq', 'dqq']
scores = [1,2,3,4,5,6,7,8]
choice = None
while choice != "0":
print("""
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
""")
choice = input("Choice:")
if choice == "0":
print("Bye!")
elif choice == "1":
print("High Scores")
for score in scores:
print(score)
elif choice == "2":
score = int(input("What score did you add?"))
scores.append(score)
elif choice == "3":
score = int(input("Remove which score?"))
if score in scores:
scores.remove(score)
else:
print(score,"isn't in the scores list.")
elif choice == "4":
scores.sort(reverse=True)
else:
print("Sorry,%d is not a valid chice.")
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:1
High Scores
1
2
3
4
5
6
7
8
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:2
What score did you add?10
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:3
Remove which score?5
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:4
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:1
High Scores
10
8
7
6
4
3
2
1
High Scores
0-Exit
1-Show Scores
2-Add a Score
3-Remove a Score
4-Sort Scores
Choice:0
Bye!
scores = []
choice = None
while choice != 0:
print("""
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
""")
choice = input("Choice:")
if choice == "0":
print("Bye!")
elif choice == "1":
print("High Scores\n")
for entry in scores:
score,name = entry
print(name,"\t",score)
elif choice == "2":
name = input("What is the player's name?")
score = int(input("What score did the player get?"))
entry = (score,name)
scores.append(entry)
scores.sort(reverse=True)
scores = scores[:5]
else:
print("Sorry,",choice,"is not valid choice.")
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
Choice:2
What is the player's name?lzq
What score did the player get?97
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
Choice:2
What is the player's name?dqq
What score did the player get?99
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
Choice:1
High Scores
dqq 99
lzq 97
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
Choice:0
Bye!
High Scores 2.0
0-Exit
1-Show Scores
2-Add a Score
