Some of the earliest computer games developed were Interactive Fiction games, in which the user’s environment is described in text, and the user makes choices using text commands.  In this problem and the next one, we’ll be developing a very simple text-based adventure game.  Every choice in this game will have exactly three options, so we can write a function that works for any of them.   Write a function selection(text, optionA, optionB, optionC), that takes in four string values.  text is a string representing a prompt in a text adventure game, and optionA, optionB, and optionC are strings representing the three possible options

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

Some of the earliest computer games developed were Interactive Fiction games, in which the user’s environment is described in text, and the user makes choices using text commands.  In this problem and the next one, we’ll be developing a very simple text-based adventure game.  Every choice in this game will have exactly three options, so we can write a function that works for any of them.

 

Write a function selection(text, optionA, optionB, optionC), that takes in four string values.  text is a string representing a prompt in a text adventure game, and optionA, optionB, and optionC are strings representing the three possible options.  

 

The function should print out the text, and then print out the options (label them with A., B., and C.).  Next, the input() function should be used to prompt the user to choose A, B, or C.  Then the function should return (not print) the one character string that represents the user’s choice: 'A', 'B', or 'C'.  If the user does not choose one of those options, then the function must print "Invalid option, defaulting to A" and then return 'A'.  

 

See the examples on the next page for an idea of how to format the printing and input functions: you don’t have to match it exactly but it should be roughly the same (you do have to match the return exactly though: returning lowercase 'a', 'b', or 'c' will cause you to fail test cases).

 

Hint:

  • When calling functions that return something like input, you generally want to assign the result to a variable so that you can access it later:  var = input(...)

    • You do need to make sure your variable names describe the value they represent, so don’t actually use var as a variable name in this problem.

Expert Solution
Step 1

Python Function: It is code defined in the block and it executed when it is called

Python function

def function_name():

    .........

    return

Python code:

#python function definition

def selection(text, optionA, optionB, optionC):

    print(text)#printting text

    print("A.",optionA)#printing optionA

    print("B.",optionA)#printing option B

    print("C.",optionA)# printing option C

    #choose is used to stre choosed option

    choose=input("Choose A, B, or C: ")

    if choose=='A':

        return 'A' #if choosen option A

    elif choose=='B':

        return 'B' #if choosen option B

    elif choose=='C':

        return 'C' #if choosen option C

    else:#if no condition is matched

        print("Invalid option, defaulting to A");

        return 'A'

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
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