Linux 에서 python 명함 예제 만 들 기

5501 단어 python명함.
카드 만 들 기주 파일:

# _*_ coding:utf-8 _*_
"""
file: cards_main.py
date: 2018-07-18 19:47
author: jiong
desc:

"""
import cards_tools
#    ,             
while True:
#TODO  ,           

 cards_tools.show_menu()

 action_str = raw_input("          : ")
 print("        %s" % action_str)
 #1,2,3       
 if action_str in ["1","2","3"]:
  if action_str == "1":
   cards_tools.new_card()
  elif action_str == "2":
   cards_tools.show_all()
  elif action_str == "3":
   cards_tools.search_card()

 #0    
 elif action_str == "0":
  print("      【      】:")

  break
  #        ,              
  #    pass   ,       ,             
  #     ,pass           
 else:
  print("    ,     :")

카드 만 들 기도구 파일

# _*_ coding:utf-8 _*_
"""
file: cards_tools.py
date: 2018-07-18 19:47
author: jiong
desc:

"""
card_list = []

def show_menu():
 """    """
 print '*' * 50
 print '    【      】'
 print ''
 print '1.    '
 print '2.    '
 print '3.    '
 print '0.    '
 print '*' * 50

def new_card():
 """    """
 print '-' * 50
 print '    '
 # 1.             
 name_str = raw_input('     :')
 phone_str = raw_input('     :')
 qq_str = raw_input('   QQ:')
 email_str = raw_input('     :')

 # 2.                 
 card_dict = {'name_str': name_str,
     'phone_str': phone_str,
     'qq_str': qq_str,
     'email_str': email_str}

 # 3.           
 card_list.append(card_dict) #              
 print card_list
 # 4.        
 print '  %s      ' % name_str

def show_all():
 """      """
 print '-' * 50
 print '      '

 #           ,    ,        
 if len(card_list) == 0:
  print '           ,           '
  # return              
  #           
  #   return         ,             
  #          
  return
 #     
 for name in ["  ", "  ", "QQ", "  "]:
  print name,
 print ''
 #      
 print '=' * 50

 #               
 for card_dict in card_list:
  # print card_dict
  print '%s\t\t%s\t\t%s\t\t%s' % (card_dict['name_str'],
          card_dict['phone_str'],
          card_dict['qq_str'],
          card_dict['email_str'])

def search_card():
 """    """
 print '-' * 50
 print '    '

 # 1.            
 find_name = raw_input('         :')
 # 2.      ,        ,      ,      
 for card_dict in card_list:
  if card_dict['name_str'] == find_name:
   print '      QQ   '
   print '=' * 50
   print '%s %s %s %s' % (card_dict['name_str'],
         card_dict['phone_str'],
         card_dict['qq_str'],
         card_dict['email_str'])

   # TODO                    
   #            ,           ,              ,     ,                    ,             ,                  ,    
   deal_card(card_dict)
   break

  else:
   print '  ,    %s' % find_name


def deal_card(find_dict):
 print find_dict
 action_str = raw_input('          '
       '[1]    [2]    :')
 #           
 if action_str == '1':
  find_dict['name_str'] = input_card_info(find_dict['name_str'], '  :')
  find_dict['phone_str'] = input_card_info(find_dict['phone_str'], '  :')
  find_dict['qq_str'] = input_card_info(find_dict['qq_str'], 'QQ:')
  find_dict['email_str'] = input_card_info(find_dict['email_str'], '  :')

  print '      !!!'
 elif action_str == '2':

  card_list.remove(find_dict)

  print '      !!!'

def input_card_info(dict_value, tip_message):


 """

 :param dict_value:       
 :param tip_message:       
 :return:         ,     ,           
 """
 # 1.        

 result_str = raw_input(tip_message)
 # 2.           ,         ,      
 if len(result_str) > 0:
  return result_str
 # 3.          ,  ‘       '
 else:
  return dict_value

실행 cardsmian 파일:
这里写图片描述  
这里写图片描述  
这里写图片描述

좋은 웹페이지 즐겨찾기