środa, 26 kwietnia 2017

Menu build in python with KeyboardInterrupt exception

import sys
import os
import requests

def print_menu():

    print 30 * "-", "MENU", 30 * "-"
    print "1. Call Date"
    print "2. Check logged users"
    print "3. GET Request"
    print "4. Exit"
    print 67 * "-"

loop = True
try:
      while loop:
            print_menu()
            choice = input("enter your choice [1-4]: ")
            if choice == 1:
                  x = os.system('date')
                  print x
            elif choice == 2:
                  print "logged uers"
                  os.system('who')
            elif choice == 3:
                  address = 'https://google.com'
                  print "GET Request of {}".format(address)
                  req = requests.get(address)
                  print(req.encoding)
                  print(req.status_code)
            else:
                  print "exit"
                  sys.exit()
except KeyboardInterrupt:

Brak komentarzy:

Prześlij komentarz