-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWord Processing.py
34 lines (28 loc) · 1.06 KB
/
Word Processing.py
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
# -*- coding: utf-8 -*-
"""Python 102 - Assignment 2
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1vwKnVUnLjPzv8og5_56sTWgoikLIMDqc
"""
def get_guessed_word(secret_word, letters_guessed):
guess = ''
for ch in secret_word:
if ch in letters_guessed:
guess = guess + ch
else:
guess = guess + ' _ '
return guess
print(get_guessed_word('computer', ['c', 'w', 'm', 'r'])) # c _ m _ _ _ _ r
print(get_guessed_word('programming', ['c', 'p', 'm', 'a', 'r'])) # pr _ _ ramm _ _ _ '
print(get_guessed_word('america', ['c', 'p', 'm', 'a', 'r'])) # am _ r_ ca'
def get_available_letters(letters_guessed):
import string
alphabet = string.ascii_lowercase
alpha = ''
for letter in alphabet:
if letter not in letters_guessed:
alpha = alpha + letter
return alpha
print(get_available_letters(['a', 'b', 'c'])) # "def...z"
print(get_available_letters(['p', 'q', 'r'])) # "abc... z" (everything except pqr)
print(get_available_letters(['b', 'o', 'x'])) # "ac... z" (everything except b, o, x)