Answer to Question #304486 in Python for Kate

Question #304486

Create a program that asks the user to guess the color.


1
Expert's answer
2022-03-01T09:36:46-0500
import random
colors = ['red', 'grren', 'blue', 'gray', 'black', 'white', 'orange']
color = random.choice(colors)

print('I have chosen a color')
print('It may be ', end='')
for c in colors:
    print(c, end=' ')
print()

guess = '' 
count = 0
while guess != color:
    print('Try to guess it', end=' ')
    guess = input()
    count += 1
    if guess != color:
        print('No, it is not')
    else:
        print('Yes, you are right)
    
print(f'You have guessed it in {count} times')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS