-1

What do I fix to allow users to enter 'Version' , 'Credit' , 'Info', 'Notes' and 'Credit' in any order?

Here is the code I tried :

if(answer == 'Debug'):
    print('Type the word in the debug screen\nto get an output, '
          'ex. Type "Version"\nto find the file Version.')
print('\033[1;34;40m============')
print('\033[1;39;40mVersion')
print('\033[1;33;40mCredit')
print('\033[1;34;40mInfo')
print('\033[1;32;40mNotes')
answer=raw_input()
if(answer == 'Version'):
    print('\033[1;39;39m1.2.2')
if(answer == 'Credit'):
    print('\033[1;33;40mXendos6 2/22/19')
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 3
    Hi, welcome to StackOverflow! Please, if you can, take a look at [ask]. Can you please elaborate more on the question? Posting a [mcve] is usually advisable to allow others to answer faster and better. – bracco23 Mar 01 '19 at 13:11
  • What exactly is the problem with your code? – martineau Mar 01 '19 at 13:21
  • Some of the answers to the question [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) may help. – martineau Mar 01 '19 at 13:23
  • The problem is I want the user to be able to type the keywords in any order, but with the code right now they have to do it in order of Version, Credit, Info and Notes if they don't it just quits. – Chillthuggin1 Mar 01 '19 at 15:09

2 Answers2

0

Please take a look at this. Maybe this will solve your issue.

responses = {
    'version': '1.0.1',
    'credit': 'some_credit',
    'info': 'this is info',
    'debug': 'this is debug output'
}

for i in responses.keys():
    user_input = input('Please enter a choice from {}: '.format(options))
    print(responses.get(user_input))

Note: this is just a template

sanster_23
  • 800
  • 10
  • 17
  • 2
    You don't need the `options` list, and it repeats data. `responses.keys()` can be used instead. Note that the OP is using the old python 2, judging from the use of `raw_input()`. – cdarke Mar 01 '19 at 13:28
0

You can use a dictionary consisting of each question with the printed reply, for example:

menu = {'Version': '1.2.2', 'Credit': 'Xendos6 2/22/19', 'Info': 'Some information'}

print('\033[1;34;40m============')
for k in menu.keys():
    print('\033[1;39;40m', k)

answer = raw_input()
if answer in menu:
    print('\033[1;39;39m', menu[answer])
else:
    print("Invalid answer:", answer)

This makes the menu much easier to add items to. If the code to execute is more complex than a simple text string then the action can be placed in a function, one for each menu item, and the function name used as the value. The function is then called as menu[answer]().

EDIT: It now appears that the OP needs a loop. Here is an example that removes each entry from the menu as it is chosen:

menu = {'Version': '1.2.2', 'Credit': 'Xendos6 2/22/19', 'Info': 'Some information'}

while menu:
    print('\033[1;34;40m============')
    for k in menu.keys():
        print('\033[1;39;40m', k)

    answer = raw_input()
    if answer in menu:
        print('\033[1;39;39m', menu[answer])
        del(menu[answer])
    else:
        print("Invalid answer:", answer)

This deletes the key when an item is chosen. The loop continues while menu has data items in it - while menu: will be false when menu is empty.

cdarke
  • 42,728
  • 8
  • 80
  • 84
  • EDIT When I type 1 thing it quits. – Chillthuggin1 Mar 01 '19 at 15:08
  • @Chillthuggin1: yes, you did not ask for anything else, your original code did the same thing, but that was not in your question. – cdarke Mar 02 '19 at 10:22
  • to allow MULTIPLE inputs in ANY ORDER it says it. – Chillthuggin1 Mar 02 '19 at 22:52
  • @Chillthuggin1 : OK, so does my second solution work for you or not? In future, please try harder to explain what you need, don't just put a statement in the title (which is different to what you say in your comment). Decide whether you actually want people to help you or not. – cdarke Mar 03 '19 at 12:07