Upload wordjumble.py
Browse files- wordjumble.py +35 -0
wordjumble.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""WordJumble
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/15l1pcWotDAP9FFZKbStGfOd1SF_LMsWs
|
8 |
+
"""
|
9 |
+
|
10 |
+
import random
|
11 |
+
|
12 |
+
def scramble_word(word):
|
13 |
+
word_list = list(word)
|
14 |
+
random.shuffle(word_list)
|
15 |
+
return ''.join(word_list)
|
16 |
+
|
17 |
+
def play_game(words):
|
18 |
+
score = 0
|
19 |
+
for word in words:
|
20 |
+
scrambled_word = scramble_word(word)
|
21 |
+
print(f"Scrambled word: {scrambled_word}")
|
22 |
+
|
23 |
+
guess = input("Your guess: ")
|
24 |
+
|
25 |
+
if guess.lower() == word.lower():
|
26 |
+
print("Correct!\n")
|
27 |
+
score += 1
|
28 |
+
else:
|
29 |
+
print(f"Wrong! The correct word was '{word}'.\n")
|
30 |
+
|
31 |
+
print(f"Game over! Your final score is {score} out of {len(words)}.")
|
32 |
+
|
33 |
+
words = ["python", "developer", "chatgpt", "algorithm", "keyboard"]
|
34 |
+
|
35 |
+
play_game(words)
|