-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumble_word.py
More file actions
66 lines (55 loc) · 1.91 KB
/
Copy pathjumble_word.py
File metadata and controls
66 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
def choose():
# List of words to choose from
words = ['apple', 'giraffe', 'computer', 'sunshine', 'pyramid', 'jungle', 'exploration', 'adventure', 'marathon', 'universe']
# Randomly select a word from the list
pick = random.choice(words)
return pick
def jumble(word):
# Randomly shuffle the letters of the word to create a jumbled version
jumbled = "".join(random.sample(word, len(word)))
return jumbled
def thank(p1n, p2n, p1, p2):
# Display final scores and thank the players
print(f"{p1n}, Your score is: {p1}")
print(f"{p2n}, Your score is: {p2}")
print("Thanks for playing!")
print("Have a nice day!")
def play():
# Get player names
p1n = input("Player 1, please enter your name: ")
p2n = input("Player 2, please enter your name: ")
# Initialize scores and turn
pp1 = 0
pp2 = 0
turn = 0
while True:
# Choose a word and jumble it
picked_word = choose()
qn = jumble(picked_word)
print("Jumbled word is:", qn)
# Determine whose turn it is
if turn % 2 == 0:
print(f"{p1n}, your turn!")
ans = input("What is your guess? ")
if ans == picked_word:
pp1 += 1
print("Correct! Your score is:", pp1)
else:
print("Better luck next time!")
turn += 1
else:
print(f"{p2n}, your turn!")
ans = input("What is your guess? ")
if ans == picked_word:
pp2 += 1
print("Correct! Your score is:", pp2)
else:
print("Better luck next time!")
turn += 1
# Check if either player wants to quit the game
if turn >= 10: # Example condition: 10 rounds
thank(p1n, p2n, pp1, pp2)
break
# Start the game
play()