接受多个答案作为'如果'变量

时间:2018-02-02 14:26:47

标签: python python-3.x

我如何接受输入的多个选项/答案。例如:

if player_ship == 'Transport' or 'TRANSPORT' or 'transport':
        print('You successfully purchased a Transport Ship!\n\n')

1 个答案:

答案 0 :(得分:1)

以下内容将确保区分大小写不是问题。

const Client = require('ssh2').Client;
const conn = new Client();

const encode = 'utf8';
const connection = {
  host: '100.10.101.11',
  username: 'admin',
  password: 'c0mm0nU53rP455'
}

conn.on('ready', function() {
  // avoid the use of console.log due to it adds a new line at the end of
  // the message
  process.stdout.write('Connection :: ready');

  let password = 'y0urR007p455w0rd';
  let command = '';
  let pwSent = false;
  let su = false;
  let commands = [
    `su`,
    `ls /root`,
    `touch /media/delete_me.txt`,
    `rm /media/delete_me.txt` // be carefull with this type of commands
  ];

  conn.shell((err, stream) => {
    if (err) {
      console.log(err);
    }

    stream.on('exit', function (code) {
      process.stdout.write('Connection :: exit');
      conn.end();
    });

    stream.on('data', function(data) {
      process.stdout.write(data.toString(encode));

      // handle su password prompt
      if (command.indexOf('su') !== -1 && !pwSent) {
         /*
         * if su has been sent a data event is triggered but the
         * first event is not the password prompt, this will ignore the
         * first event and only respond when the prompt is asking
         * for the password
         */
         if (command.indexOf('su') > -1) {
            su = true;
         }
         if (data.indexOf(':') >= data.length - 2) {
            pwSent = true;
            stream.write(password + '\n');
         }
      } else {
        // detect the right condition to send the next command
        let dataLength = data.length > 2;
        let commonCommand = data.indexOf('$') >= data.length - 2;
        let suCommand = data.indexOf('#') >= data.length - 2;

        if (dataLength && (commonCommand || suCommand )) {

          if (commands.length > 0) {
            command = commands.shift();
            stream.write(command + '\n');

          } else {
            // su requires two exit commands to close the session
            if (su) {
               su = false;
               stream.write('exit\n');
            } else {
               stream.end('exit\n');
            }
          }
        }
      }
    });

    // first command
    command = commands.shift();
    stream.write(command + '\n');
  });
}).connect(connection);

如果您真的需要检查特定值,这将有效:

 public IHttpActionResult getProduct()
        {

             // cache for 5 minutes:

             if( 5 min cache == null){


                 // call another services url
                 }

        else{
         // taken from  5 MIN cache.
         }


   // cache available take from 5 minutes cache data.

        next : // cache for 2 hours 

             if(2  hours cache != null){
               // get an original data

             }
       //cache available take from 2 hours cache data.




       // add the values in single response as json.
          return  response;

        }