Skip to content

Commit 98f5cab

Browse files
committed
Day 4
- Randomization and Python Lists
1 parent 30b3907 commit 98f5cab

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Day 1](https://github.com/a092devs/100-days-of-python/tree/master/day01) - Working with Variables in Python to Manage Data
66
- [Day 2](https://github.com/a092devs/100-days-of-python/tree/master/day02) - Understanding Data Types and How to Manipulate Strings
77
- [Day 3](https://github.com/a092devs/100-days-of-python/tree/master/day03) - Control FLow and Logical Operators
8+
- [Day 4](https://github.com/a092devs/100-days-of-python/tree/master/day04) - Randomization and Python Lists
89

910

1011
## ⚙ Tools and Technologies Covered

day04/banker_rouletter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Import the random module here
2+
import random
3+
# Split string method
4+
names_string = input("Give me everybody's names, separated by a comma. ")
5+
names = names_string.split(", ")
6+
# 🚨 Don't change the code above 👆
7+
8+
# Write your code below this line 👇
9+
length = len(names)
10+
name_index = random.randint(0, length - 1)
11+
print(f"{names[name_index]} is going to buy the meal today!")

day04/coin_flip.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Remember to use the random module
2+
# Hint: Remember to import the random module here at the top of the file. 🎲
3+
4+
# Write the rest of your code below this line 👇
5+
import random
6+
7+
coin_flip = random.randint(0,1)
8+
if coin_flip == 1:
9+
print("Heads")
10+
else:
11+
print("Tails")

day04/rock_paper_scissors.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import random
2+
3+
rock = '''
4+
_______
5+
---' ____)
6+
(_____)
7+
(_____)
8+
(____)
9+
---.__(___)
10+
'''
11+
12+
paper = '''
13+
_______
14+
---' ____)____
15+
______)
16+
_______)
17+
_______)
18+
---.__________)
19+
'''
20+
21+
scissors = '''
22+
_______
23+
---' ____)____
24+
______)
25+
__________)
26+
(____)
27+
---.__(___)
28+
'''
29+
30+
game_arts = [rock, paper, scissors]
31+
32+
user_choice = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\n"))
33+
if user_choice >= 3 or user_choice < 0:
34+
print("You typed an invalid number, You Lose. ☠")
35+
else:
36+
print(game_arts[user_choice])
37+
38+
computer_choice = random.randint(0, 2)
39+
print("Computer chose:")
40+
print(game_arts[computer_choice])
41+
42+
if user_choice == 0 and computer_choice == 2:
43+
print("You win! 🎉")
44+
elif computer_choice == 0 and user_choice == 2:
45+
print("You lose. ☠")
46+
elif computer_choice > user_choice:
47+
print("You lose. ☠")
48+
elif user_choice > computer_choice:
49+
print("You win! 🎉")
50+
elif computer_choice == user_choice:
51+
print("It's a draw.")

day04/treasure_map.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 🚨 Don't change the code below 👇
2+
row1 = ["⬜️","️⬜️","️⬜️"]
3+
row2 = ["⬜️","⬜️","️⬜️"]
4+
row3 = ["⬜️️","⬜️️","⬜️️"]
5+
my_list = [row1, row2, row3]
6+
print(f"{row1}\n{row2}\n{row3}")
7+
position = input("Where do you want to put the treasure? ")
8+
# 🚨 Don't change the code above 👆
9+
10+
# Write your code below this row 👇
11+
horizontal = int(position[0])
12+
vertical = int(position[1])
13+
14+
my_list[vertical - 1][horizontal - 1] = "X"
15+
16+
# Write your code above this row 👆
17+
18+
# 🚨 Don't change the code below 👇
19+
print(f"{row1}\n{row2}\n{row3}")

0 commit comments

Comments
 (0)