3535 "hard" : {"min_length" : 9 , "max_length" : 100 , "points" : 20 },
3636}
3737
38+
3839def main ():
3940 global _ , again , attempts , base_points , bonus , category , difficulty , fancy_scrambled , filtered_words , grade , hint_used , letters , lives , lives_str , max_attempts , raw , remaining , round_num , score , scrambled , settings , still_playing , valid_words , word , words
4041 while True :
@@ -72,7 +73,8 @@ def main():
7273 settings = DIFFICULTY_LEVELS [difficulty ]
7374 valid_words = []
7475 for category , words in WORD_BANK .items ():
75- filtered_words = [w for w in words if settings ["min_length" ] <= len (w ) <= settings ["max_length" ]]
76+ filtered_words = [w for w in words if settings ["min_length" ] <= len (
77+ w ) <= settings ["max_length" ]]
7678 if filtered_words :
7779 valid_words .append ((category , filtered_words ))
7880
@@ -86,7 +88,7 @@ def main():
8688 scrambled = "" .join (letters )
8789 if scrambled != word :
8890 break
89-
91+
9092 fancy_scrambled = " " .join (scrambled .upper ())
9193
9294 hint_used = False
@@ -99,13 +101,15 @@ def main():
99101 print ("║ 🔤 W O R D S C R A M B L E 🔤 ║" )
100102 print ("╠══════════════════════════════════════════════╣" )
101103 lives_str = "❤️ " * lives + "🖤 " * (3 - lives )
102- print (f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
104+ print (
105+ f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
103106 print (f"║ Difficulty: { difficulty .capitalize ():<31} ║" )
104107 print ("╚══════════════════════════════════════════════╝\n " )
105108
106109 print (f" 🔀 Unscramble this word:\n " )
107110 print (f" ✨ { fancy_scrambled } ✨\n " )
108- print (f" Letters: { len (word )} | Attempts left this round: { max_attempts - attempts } " )
111+ print (
112+ f" Letters: { len (word )} | Attempts left this round: { max_attempts - attempts } " )
109113
110114 if hint_used :
111115 print (f" 💡 Hint: { category } " )
@@ -147,17 +151,20 @@ def main():
147151 print ("╔══════════════════════════════════════════════╗" )
148152 print ("║ 🔤 W O R D S C R A M B L E 🔤 ║" )
149153 print ("╠══════════════════════════════════════════════╣" )
150- print (f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
154+ print (
155+ f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
151156 print (f"║ Difficulty: { difficulty .capitalize ():<31} ║" )
152157 print ("╚══════════════════════════════════════════════╝\n " )
153-
154- print (f"\n 🎉 Correct! +{ bonus } points { '(hint used: half points)' if hint_used else '' } \n " )
158+
159+ print (
160+ f"\n 🎉 Correct! +{ bonus } points { '(hint used: half points)' if hint_used else '' } \n " )
155161 time .sleep (1.5 )
156162 break
157163 else :
158164 remaining = max_attempts - attempts
159165 if remaining > 0 :
160- print (f"\n ❌ Nope! Try again. ({ remaining } attempt{ 's' if remaining != 1 else '' } left)" )
166+ print (
167+ f"\n ❌ Nope! Try again. ({ remaining } attempt{ 's' if remaining != 1 else '' } left)" )
161168 time .sleep (1 )
162169 else :
163170 lives -= 1
@@ -166,32 +173,42 @@ def main():
166173 print ("║ 🔤 W O R D S C R A M B L E 🔤 ║" )
167174 print ("╠══════════════════════════════════════════════╣" )
168175 lives_str = "❤️ " * lives + "🖤 " * (3 - lives )
169- print (f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
176+ print (
177+ f"║ Round: { round_num :<5} Score: { score :<6} Lives: { lives_str :<14} ║" )
170178 print (f"║ Difficulty: { difficulty .capitalize ():<31} ║" )
171179 print ("╚══════════════════════════════════════════════╝\n " )
172-
173- print (f"\n 💔 Out of attempts! The word was: { word .upper ()} \n " )
180+
181+ print (
182+ f"\n 💔 Out of attempts! The word was: { word .upper ()} \n " )
174183 time .sleep (2 )
175184 break
176185
177186 if still_playing :
178187 round_num += 1
179188
180- os .system ("cls" if os .name == "nt" else "clear" )
181- print ("\n ╔══════════════════════════════════╗" )
182- print (" ║ 💀 GAME OVER 💀 ║" )
183- print (" ╚══════════════════════════════════╝\n " )
184- print (f" You survived { round_num } round{ 's' if round_num != 1 else '' } ." )
185- print (f" Final score: { score } points\n " )
186-
187- grade = (
188- "🏆 Wordsmith Supreme!" if score >= 80 else
189- "🥇 Excellent!" if score >= 60 else
190- "🥈 Good effort!" if score >= 40 else
191- "🥉 Keep practising!" if score >= 20 else
192- "📚 Hit the dictionary!"
193- )
194- print (f" { grade } \n " )
189+ if still_playing :
190+ os .system ("cls" if os .name == "nt" else "clear" )
191+ print ("\n ╔══════════════════════════════════╗" )
192+ print (" ║ 💀 GAME OVER 💀 ║" )
193+ print (" ╚══════════════════════════════════╝\n " )
194+ print (
195+ f" You survived { round_num } round{ 's' if round_num != 1 else '' } ." )
196+ print (f" Final score: { score } points\n " )
197+
198+ grade = (
199+ "🏆 Wordsmith Supreme!" if score >= 80 else
200+ "🥇 Excellent!" if score >= 60 else
201+ "🥈 Good effort!" if score >= 40 else
202+ "🥉 Keep practising!" if score >= 20 else
203+ "📚 Hit the dictionary!"
204+ )
205+ print (f" { grade } \n " )
206+ else :
207+ os .system ("cls" if os .name == "nt" else "clear" )
208+ print ("\n Thanks for playing! 👋\n " )
209+
210+ if not still_playing :
211+ break
195212
196213 try :
197214 again = input (" Play again? (y/n): " ).strip ().lower ()
0 commit comments