How would the flowchart for this code look like? # -*- coding: utf-8 -*- """ Created on Sun Dec 13 11:29:07 2020 @author: Emily Giron """ #this functions checks if the user has entered only 3 numbers def check_num(number): while(number < 100 or number > 1000): print("\nYou did not enter a 3 digit number, please enter a 3 digit number") number = int(input("Guess the number: ")) import random while True: print("Welcome to the Mastermind game!") print("\nAll you have to do is to guess a three digit number in the least amount of tries!") num = random.randrange(100, 1000) n = int(input("I'm thinking of a 3 digit number... Guess the number: ")) check_num(n) #if player guess right on first try if (n == num): print("Great! You guessed the number in just 1 try! You're a Mastermind!") else: #number of tries ctr = 0 # while loop repeats as long as the # Player fails to guess the number correctly. while (n != num): # variable increments every time the loop # is executed, giving an idea of how many # guesses were made. ctr += 1 count = 0 # explicit type conversion of an integer to # a string in order to ease extraction of digits n = str(n) # explicit type conversion of a string to an integer num = str(num) # correct[] list stores digits which are correct correct = ['X']*3 # for loop runs 4 times since the number has 4 digits. for i in range(0, 3): # checking for equality of digits if (n[i] == num[i]): # number of digits guessed correctly increments count += 1 # hence, the digit is stored in correct[]. correct[i] = n[i] else: continue # when not all the digits are guessed correctly. if (count < 3) and (count != 0): print("Not quite the number. But you did get ", count, " digit(s) correct!") print("Also these numbers in your input were correct.") for k in correct: print(k, end=' ') print('\n') print('\n') n = int(input("Enter your next choice of numbers: ")) check_num(n) # when none of the digits are guessed correctly. elif (count == 0): print("None of the numbers in your input match.") n = int(input("Enter your next choice of numbers: ")) check_num(n) # condition for equality. if n == num: print("You've become a Mastermind!") print("It took you only", ctr, "tries.") #when the user guessed the right number, ask to play again play_again = input("Do you want to play again? (y/n): ") while play_again not in ["y", "n", "Y", "N"]: print(play_again) play_again = input("Please enter y to continue or n to quit: ") if play_again == "n" or play_again == "N": print("Thanks for playing!") break

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How would the flowchart for this code look like?

# -*- coding: utf-8 -*-
"""
Created on Sun Dec 13 11:29:07 2020

@author: Emily Giron
"""
#this functions checks if the user has entered only 3 numbers
def check_num(number):
while(number < 100 or number > 1000):
print("\nYou did not enter a 3 digit number, please enter a 3 digit number")
number = int(input("Guess the number: "))


import random

while True:
print("Welcome to the Mastermind game!")
print("\nAll you have to do is to guess a three digit number in the least amount of tries!")

num = random.randrange(100, 1000)

n = int(input("I'm thinking of a 3 digit number... Guess the number: "))
check_num(n)


#if player guess right on first try
if (n == num):
print("Great! You guessed the number in just 1 try! You're a Mastermind!")
else:
#number of tries
ctr = 0

# while loop repeats as long as the
# Player fails to guess the number correctly.
while (n != num):
# variable increments every time the loop
# is executed, giving an idea of how many
# guesses were made.
ctr += 1

count = 0

# explicit type conversion of an integer to
# a string in order to ease extraction of digits
n = str(n)

# explicit type conversion of a string to an integer
num = str(num)

# correct[] list stores digits which are correct
correct = ['X']*3

# for loop runs 4 times since the number has 4 digits.
for i in range(0, 3):

# checking for equality of digits
if (n[i] == num[i]):
# number of digits guessed correctly increments
count += 1
# hence, the digit is stored in correct[].
correct[i] = n[i]
else:
continue

# when not all the digits are guessed correctly.
if (count < 3) and (count != 0):
print("Not quite the number. But you did get ", count, " digit(s) correct!")
print("Also these numbers in your input were correct.")
for k in correct:
print(k, end=' ')
print('\n')
print('\n')
n = int(input("Enter your next choice of numbers: "))
check_num(n)

# when none of the digits are guessed correctly.
elif (count == 0):
print("None of the numbers in your input match.")
n = int(input("Enter your next choice of numbers: "))
check_num(n)

# condition for equality.
if n == num:
print("You've become a Mastermind!")
print("It took you only", ctr, "tries.")

#when the user guessed the right number, ask to play again
play_again = input("Do you want to play again? (y/n): ")
while play_again not in ["y", "n", "Y", "N"]:
print(play_again)
play_again = input("Please enter y to continue or n to quit: ")
if play_again == "n" or play_again == "N":
print("Thanks for playing!")
break

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Unary Predicate
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education