Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6501f90

Browse files
2 new projects in Beginner.
1 parent ee5715b commit 6501f90

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

‎Beginner/10_rock_paper_scissors.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import random
2+
3+
options = ["rock", "paper", "scissors"]
4+
5+
# Allow for replays using a while loop
6+
while True:
7+
# Get the user's choice
8+
user_choice = input("Choose rock, paper, or scissors: ").lower()
9+
# Validation
10+
if user_choice not in options:
11+
print("Invalid choice. Please choose rock, paper, or scissors.")
12+
continue
13+
14+
# Choose a random computer choice
15+
computer_choice = random.choice(options)
16+
print(f"Computer chose {computer_choice}.")
17+
18+
# Determine the winner
19+
if user_choice == computer_choice:
20+
print("It's a tie!")
21+
elif (user_choice == "rock" and computer_choice == "scissors") or \
22+
(user_choice == "paper" and computer_choice == "rock") or \
23+
(user_choice == "scissors" and computer_choice == "paper"):
24+
print("You win!")
25+
else:
26+
print("You lose!")
27+
28+
# Ask if the user wants to play again
29+
play_again = input("Play again? (yes/no): ").lower()
30+
if play_again != "yes":
31+
break

‎Beginner/11_mad_libs_generator.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Create the main function for easy insertion
2+
def mad_libs(story):
3+
words = {}
4+
for word_type in story["word_types"]:
5+
words[word_type] = input(f"Enter a {word_type}: ")
6+
7+
filled_story = story["template"].format(**words)
8+
print(filled_story)
9+
10+
# Predefine some stories
11+
stories = [
12+
{
13+
"name": "The Lost Something...",
14+
"word_types": ["adjective", "noun", "verb", "adverb", "place"],
15+
"template": "One day, a {adjective} {noun} decided to {verb} {adverb} to the {place}, never to be seen again..."
16+
},
17+
{
18+
"name": "The Birthday Party?",
19+
"word_types": ["adjective", "noun", "verb", "number", "food"],
20+
"template": "For my birthday, I had a {adjective} party with {number} {noun}s. We {verb} and ate lots of {food}."
21+
},
22+
{
23+
"name": "The School Trip...",
24+
"word_types": ["adjective", "noun", "verb", "place", "animal"],
25+
"template": "Our school trip was very {adjective}. We saw a {noun} {verb} at the {place} and even a {animal}! But then the {animal} wanted to {verb} us!"
26+
},
27+
{
28+
"name": "The Alien Invasion",
29+
"word_types": ["adjective", "noun", "verb", "adverb", "plural_noun"],
30+
"template": "Suddenly, a {adjective} spaceship landed in my backyard! A {noun} alien jumped out and started to {verb} {adverb} with my {plural_noun}! I didn't think {noun} aliens could do that."
31+
}
32+
]
33+
34+
35+
print("Welcome to Mad Libs!")
36+
for i, story in enumerate(stories):
37+
print(f"{i+1}. {story['name']}")
38+
39+
while True:
40+
try:
41+
choice = int(input("Choose a story (1-4): "))
42+
if 1 <= choice <= len(stories):
43+
break
44+
else:
45+
print("Invalid choice. Please enter a number between 1 and 4.")
46+
except ValueError:
47+
print("Invalid input. Please enter a number.")
48+
49+
mad_libs(stories[choice - 1])

‎README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,76 @@ These projects are ideal for those new to Python. Each project includes a descri
323323

324324
</details>
325325

326+
### 10. Rock Paper Scissors
327+
- **Description**: Create a rock paper scissors game.
328+
329+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/10_rock_paper_scissors.py
330+
331+
- **Steps**:
332+
1. Prompt the user for a choice.
333+
2. Generate a random choice for the computer.
334+
3. Compare the choices.
335+
4. Display the results.
336+
337+
- **Tips:**
338+
339+
</summary>
340+
<details><summary>Tip 1:</summary>
341+
342+
Use `input()` for input.
343+
344+
</details>
345+
<details><summary>Tip 2:</summary>
346+
347+
Use `random.choice()` to generate a random choice for the computer.
348+
349+
</details>
350+
<details><summary>Tip 3:</summary>
351+
352+
Use `conditional` statements to compare the choices and determine the winner.
353+
354+
</details>
355+
<details><summary>Tip 4:</summary>
356+
357+
Print out the results using `print()`.
358+
359+
</details>
360+
361+
### 11. Mad Libs Generator
362+
- **Description**: Create a Mad Libs generator.
363+
364+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/11_mad_libs_generator.py
365+
366+
- **Steps**:
367+
1. Define a template for the Mad Libs story.
368+
2. Prompt the user for different types of words (noun, verb, adjective, etc.).
369+
3. Replace the placeholders in the template with the user's words.
370+
4. Display the completed Mad Libs story.
371+
372+
- **Tips:**
373+
374+
</summary>
375+
<details><summary>Tip 1:</summary>
376+
377+
Use `input()` for input.
378+
379+
</details>
380+
<details><summary>Tip 2:</summary>
381+
382+
Use string formatting to replace the placeholders in the template.
383+
384+
</details>
385+
<details><summary>Tip 3:</summary>
386+
387+
Create multiple templates for different stories.
388+
389+
</details>
390+
<details><summary>Tip 4:</summary>
391+
392+
Print out the results using `print()`.
393+
394+
</details>
395+
326396
> [!NOTE]
327397
> Working code solutions are in the `/Beginner` folder.
328398

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /