import uagame import random def main(): #set up the list list_of_words=[\"apple\
ID: 3756024 • Letter: I
Question
import uagame
import random
def main():
#set up the list
list_of_words=["apple","banana","kiwi","mango","pineapple","watermelon"]
word=random.choice(list_of_words)
print(word)
list1=[]
count=0
for x in word:
list1.append(x)
count=count+1
# create window
screen_width=500
screen_height=400
window = uagame.Window("Word Puzzle", screen_width, screen_height)
# Display instructions
y_coord=0
window.draw_string("I am thinking of a secret word",0,y_coord)
font_height=window.get_font_height()
y_coord=y_coord+font_height
window.draw_string("Try and guess the word. You can guess one letter at a time.",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("Each time you guess I will show you",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("which letters have been correctly guessed and which",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("letters are still missing. You will have 4 guesses to",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("guess all of the letters.Good luck!",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("The answer so far is: "+ "_ "*count,0,y_coord)
y_coord=y_coord+font_height
#Input answer
guess=window.input_string("Guess a letter: ",0,y_coord)
y_coord=y_coord+font_height
letter=list(word)
underline=list('_ '*count)
#check answer
if guess in letter:
for x in range(len(letter)):
if guess == letter[x]:
underline[x] = guess
final_answer = ''.join(underline)
y_coord=y_coord+font_height
window.draw_string("The answer so far is: "+final_answer+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Good job! You found the word "+word+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Press enter to end the game",0,y_coord)
window.close()
else:
window.draw_string("The answer so far is: "+"_ "*count,0,y_coord)
y_coord=y_coord+font_height
window.draw_string("Not quite, the correct word was "+word+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Press enter to end the game",0,y_coord)
window.close()
main()
Word Puzzle V2 Reflection Activity
Question 1 [4]
List two simple statement kinds and two compound statement kinds (excluding function definition) that were used in your V2 code. [4]
Two simple statement kinds used:
Two compound statement kinds used:
Question 2 [6]
Provide an example from your code for each instance of the four statement kinds you listed in Q1 in order (simple, simple, compound, compound). For the compound statements, highlight the header(s) in yellow [6]
Question 3 [3]
How would you need to modify your code if the rules for this version were changed so that you only displayed the “success” message if the player guessed a letter which occurred more than once in the secret word? For example, with the word ‘kiwi’, the player should see the success message if they guess an ‘i’ , but not if they guess ‘k’ or ‘w’. [3]
can you do the reflection activity for me?? Thanks!!!
Two simple statement kinds used:
Two compound statement kinds used:
Explanation / Answer
please do upvote.If you have any problem do comment and i shall be happy to help you.Thanks for using chegg.
Note: please indent modified code using screenshot given below.Since python's indentation is undone due to cheggs technical error.
changed/modified code is in bold
Note: you should have uagame module with you to run the program.
-----------------------
explaination:
simple statement ------------>it is usually of single line. e.g import,return,delete,assignment etc
compund statement--------->It is usually of multiple lines.Execution of other statments are controlled by them.e.g if,for etc
1.
two kinds of simple statements used
import
assignment
two kinds of coumpound statements used are
if
for
2.
import------->import uagame
assignment----->list_of_words=["apple","banana","kiwi","mango","pineapple","watermelon"]
compund statments consists of one or more clauses.
each clause is of usually form--------->header : suite
if------>if guess == letter[x](header):
underline[x] = guess
for---------->for x in word(header):
list1.append(x)
count=count+1
3)
note:modified code is in bold
-----------
import uagame
import random
def main():
#set up the list
list_of_words=["apple","banana","kiwi","mango","pineapple","watermelon"]
word=random.choice(list_of_words)
print(word)
list1=[]
count=0
for x in word:
list1.append(x)
count=count+1
# create window
screen_width=500
screen_height=400
window = uagame.Window("Word Puzzle", screen_width, screen_height)
# Display instructions
y_coord=0
window.draw_string("I am thinking of a secret word",0,y_coord)
font_height=window.get_font_height()
y_coord=y_coord+font_height
window.draw_string("Try and guess the word. You can guess one letter at a time.",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("Each time you guess I will show you",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("which letters have been correctly guessed and which",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("letters are still missing. You will have 4 guesses to",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("guess all of the letters.Good luck!",0,y_coord)
y_coord=y_coord+font_height
window.draw_string("The answer so far is: "+ "_ "*count,0,y_coord)
y_coord=y_coord+font_height
#Input answer
guess=window.input_string("Guess a letter: ",0,y_coord)
y_coord=y_coord+font_height
letter=list(word)
underline=list('_ '*count)
repeated_letters=set()#creating an empty set
#iterating through each letter and if their count is more then 1 they are added to set repeated_letters
for c in letter:
if(letters.count(c)>1):
repeated_letters.add(c)
#check answer
repeated_letters=list(repeated_letters)#converting back from set to list
#using repeated_letters instead of letter
if guess in repeated_letters:
for x in range(len(repeated_letters)):
if guess == repeated_letters[x]:
underline[x] = guess
final_answer = ''.join(underline)
y_coord=y_coord+font_height
window.draw_string("The answer so far is: "+final_answer+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Good job! You found the word "+word+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Press enter to end the game",0,y_coord)
window.close()
else:
window.draw_string("The answer so far is: "+"_ "*count,0,y_coord)
y_coord=y_coord+font_height
window.draw_string("Not quite, the correct word was "+word+"",0,y_coord)
y_coord=y_coord+font_height
window.input_string("Press enter to end the game",0,y_coord)
window.close()
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.