1 Star 0 Fork 0

CatCoder / Python Demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pythonScript.py 19.40 KB
一键复制 编辑 原始数据 按行查看 历史
CatCoder 提交于 2018-06-15 15:15 . Upload pythonScript.py
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
# name = ''
# while not name:
# print('Enter your name:')
# name = input()
# print('How many guests will you have?')
# numberOfGuests = int(input())
# if numberOfGuests:
# print('Be sure to have enough room for all your guests.')
# print('Done')
# for i in range(numberOfGuests):
# print('Jimmy numberOfGuests Times (' + str(i) + ')')
# total = 0
# for num in range(1,101,99):
# total = total + num
# print(total)
# for i in range(5,-1,-1):
# print(i)
# import random
# for i in range(5):
# print(random.randint(1,10))
# import random, sys, os, math
# while True:
# print('Type exit to exit.')
# response = input()
# if response == 'exit':
# sys.exit()
# print('You typed '+ response +'.')
# print('Please type a int:')
# spam = int(input())
# if spam == 1:
# print('Hello')
# elif spam == 2:
# print('Howdy')
# else :
# print('Gretting')
# for i in range(0,10,1):
# print(i)
# print(round(70.8978455))
# print(round(70.8978455,1))
# print(round(70.8978455,2))
# print(round(70.8978455,3))
# print(round(70.8978455,4))
# print(abs(10))
# print(abs(-10))
# def hello(name):
# print('Hello ' + name)
# hello('Rose')
# import random
# def getAnswer(answerNum):
# if answerNum == 1:
# return 'It is certain'
# elif answerNum == 2:
# return 'It is decidedly so'
# elif answerNum == 3:
# return 'Yes'
# elif answerNum == 4:
# return 'Reply hazy try again'
# elif answerNum == 5:
# return 'Concentrate and ask again'
# elif answerNum == 6:
# return 'Ask again later'
# elif answerNum == 7:
# return 'My reply is no'
# elif answerNum == 8:
# return 'Outlook not so good'
# elif answerNum == 9:
# return 'Very doubtful'
# r = random.randint(1,9)
# fortune = getAnswer(r)
# print(fortune)
# print('Hello')
# print('World')
# print('Hello ', end='')
# print('World')
# print('cats','dogs','mice')
# print('cats','dogs','mice',sep=',')
# def spam():
# global eggs
# eggs = 'spam'
# eggs = 'global'
# spam()
# print(eggs)
# def spam(divideBy):
# try :
# return 42 / divideBy
# except ZeroDivisionError:
# print('Error:Invalid argument.')
# print(spam(2))
# print(spam(12))
# print(spam(0))
# print(spam(1))
#This is a guess the number game
# import random
# secretNumber = random.randint(1,20)
# print('I am thinking of a number between 1 and 20.')
# #Ask the player to guess 6 times
# for guessToken in range(1,7):
# print('Take a guess.')
# guess = int(input())
# if guess < secretNumber:
# print('Your guess is too low.')
# elif guess > secretNumber:
# print('Your number is too high.')
# else:
# break
# if guess == secretNumber:
# print('Good job! You guessed my number in '+ str(guessToken) +' guesses!')
# else:
# print('Nope.The number I was thinking of was '+ str(secretNumber))
# def collatz(number):
# try:
# if number == 1:
# return 1
# else:
# if number % 2 == 0:
# print(number // 2)
# collatz(number // 2)
# else :
# print(3 * number + 1)
# collatz(3 * number + 1)
# except TypeError:
# print('Error:Invalid argument type')
# print('Please Enter a Number:')
# number = int(input())
# collatz(number)
# catnames = []
# while True:
# print('Enter the name of cat ' + str(len(catnames) + 1) + ' (Or enter nothing to stop.):')
# name = input()
# if not name:
# break
# catnames = catnames + [name]
# print('The cat names are:')
# for name in catnames:
# print(' ' + name)
# cat = ['fat','black','loud']
# size,color,disposition = cat
# print(size,color,disposition)
# spam = ['hello','hi','Howdy','heyas']
# print(spam.index('hello'))
# spam.insert(2,'Good')
# print(spam)
# spam = [2,5,6,3.14,1,-7]
# spam.sort()
# print(spam)
# spam.sort(reverse=True)
# print(spam)
# spam = ['a','z','A','Z']
# spam.sort(key=str.lower)
# print(spam)
# import random
# messages = [
# 'It is certain',
# 'It is decidedly so',
# 'Yes',
# 'Reply hazy try again',
# 'Concentrate and ask again',
# 'Ask again later',
# 'Concentrate and ask again',
# 'My reply is no',
# 'Outlook not so good',
# 'Very doubtful'
# ]
# print(messages[random.randint(0,len(messages) - 1)])
# print('Hello, ' + \
# 'Tom!')
# name = 'Zophie'
# print(name[0])
# print(name[-2])
# print(name[0:4])
# print('Zo' in name)
# print('z' in name)
# print('p' not in name)
# for i in name:
# print('***' + i + '***')
# spam = 20
# cheese = spam
# spam = 40
# print(spam,cheese,sep=',')
# spam = [0,1,2,3,4,5]
# cheese = spam
# spam[1] = 'Hellp!'
# print(spam,cheese)
# spam = ['apples','bananas','tofu','cats']
# def dealSpamToStr(spam):
# targetStr = ''
# for i in range(0,len(spam)):
# if i != len(spam)-1:
# targetStr += spam[i]
# targetStr += ', '
# else:
# targetStr += 'and '
# targetStr += spam[i]
# return targetStr
# print(dealSpamToStr(spam))
# grid = [['.','.','.','.','.','.'],
# ['.','0','0','.','.','.'],
# ['0','0','0','0','.','.'],
# ['0','0','0','0','0','.'],
# ['.','0','0','0','0','0'],
# ['0','0','0','0','0','.'],
# ['0','0','0','0','.','.'],
# ['.','0','0','.','.','.'],
# ['.','.','.','.','.','.']]
# for i in range(0,len(grid[0])): # 6
# for j in range(0,len(grid)): # 9
# if j == len(grid)-1:
# print(grid[j][i],end='')
# print()
# else:
# print(grid[j][i],end='')
# birthdays = {'Alice':'Apr 1','Bob':'Dec 12','Carol':'Mar 4'}
# while True:
# print('Enter a name:(blank to quit)')
# name = input()
# if not name:
# break
# if name in birthdays:
# print(birthdays[name] + ' is the birthday of ' + name)
# else:
# print('I do not have birthday information for ' + name)
# print('What is their birthday?')
# bday = input()
# birthdays[name] = bday
# print('Birthday database updated.')
# picnicItems = {'apples':5,'cups':2}
# print(picnicItems.get('apples',0))
# print(picnicItems.get('oranges',0))
# print(picnicItems.setdefault('color','black'))
# print(picnicItems)
# import pprint
# message = 'It was a bright cold day in April,and the clocks were striking thirteen.'
# count = {}
# for character in message:
# count.setdefault(character,0)
# count[character] = count[character] + 1
# pprint.pprint(count)
# print(pprint.pformat(count))
# theBoard = {'top-L':' ','top-M':' ','top-R':' ',
# 'mid-L':' ','mid-M':' ','mid-R':' ',
# 'low-L':' ','low-M':' ','low-R':' '}
# def printBoard(board):
# print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
# print('-+-+-')
# print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
# print('-+-+-')
# print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
# turn = 'X'
# for i in range(1,9):
# printBoard(theBoard)
# print('Turn for '+ turn + '. Move on which space?')
# move = input()
# theBoard[move] = turn
# if turn == 'X':
# turn = 'O'
# else:
# turn = 'X'
# printBoard(theBoard)
# allGuests = {'Alice':{'apples':5,'pretzels':12},
# 'Bob':{'ham sandwiches':3,'apples':2},
# 'Carol':{'cups':3,'apple pies':1}}
# def totalBrought(guests,item):
# numBrought = 0
# for k,v in guests.items():
# numBrought = numBrought + v.get(item,0)
# return numBrought
# print('Number of things beging brought:')
# print(' - Apples ' + str(totalBrought(allGuests,'apples')))
# print(' - Cups ' + str(totalBrought(allGuests,'cups')))
# print(' - Cakes ' + str(totalBrought(allGuests,'cakes')))
# print(' - Ham Sandwiches ' + str(totalBrought(allGuests,'ham sandwiches')))
# stuff = {'rope':1,'torch':6,'gold coin':42,'dagger':1,'arrow':12}
# def displayInventory(inventory):
# print('Inventory:')
# item_total = 0
# for k,v in stuff.items():
# print(str(v) + ' ' + k)
# item_total += v
# print('Total number of items: ' + str(item_total))
# displayInventory(stuff)
# def displayInventory(inventory):
# print('Inventory:')
# item_total = 0
# for k,v in inventory.items():
# print(str(v) + ' ' + k)
# item_total += v
# print('Total number of items: ' + str(item_total))
# def addToInventory(inventory,addedItems):
# for item in addedItems:
# if item in inventory:
# inventory[item] = inventory[item] + 1
# else:
# inventory[item] = 1
# return inventory
# inv = {'gold coin':42,'rope':1}
# dragonLoot = ['gold coin','dragger','gold coin','gold coin','ruby','dragger']
# inv = addToInventory(inv,dragonLoot)
# displayInventory(inv)
# spam = "That is Alice's cat."
# print(spam)
# spam = 'That is Alice\'s cat.\n It\'s color is black.\t She say,\"It is so beautiful\"'
# print(spam)
# print('''
# Dear Alice,
# Eve's cat has been arrested for catnapping, cat burglary,and extortion.
# Sincerely,
# Bob
# ''')
"""
多行注释
效果验证
还真是的
鉴定完毕
"""
#****************************************************************************
# spam = 'hello'.upper().lower().isupper()
# print(spam)
# print('How are you ?')
# feeling = input()
# if feeling.lower() == 'great':
# print('I feel great too.')
# else:
# print('I hope the rest of your day is good.')
# print('hello'.isalpha()) #只包含字母并且非空
# print('hello123'.isalnum()) #只包含字母和数字并且非空
# print('1230'.isdecimal()) #只包含数字字符并且非空
# print(' '.isspace()) #只包含空格、制表符和换行并且非空
# print('This Is Title Case'.istitle()) #仅包含以大写字母开头、后面都是小写字母
# while True:
# print('Enter your age:')
# age = input()
# if age.isdecimal():
# break
# print('Please enter a number for your age.')
# while True:
# print('Selected a new password (letters and numbers only)')
# password = input()
# if password.isalnum():
# break
# print('Passwords can only have letters and numbers.')
# print(','.join(['Alice','Bob','Case']))
# print(' '.join(['Alice','Bob','Case']))
# print('---'.join(['Alice','Bob','Case']))
# print(','.join(['Alice','Bob','Case']).split())
# print(' '.join(['Alice','Bob','Case']).split())
# print('---'.join(['Alice','Bob','Case']).split('---'))
# print('''Dear Alice,
# Eve's cat has been arrested for catnapping, cat burglary,and extortion.
# Sincerely,
# Bob'''.split('\n'))
# print('hello'.rjust(20,'-'))
# print('hello'.ljust(20,'*'))
# print('hello'.center(20))
# print('hello'.center(20,'='))
# def printPicnic(itemsDict,leftWidth,rightWidth):
# print('PICNIC ITEMS'.center(leftWidth + rightWidth,'-'))
# for k,v in itemsDict.items():
# print(k.ljust(leftWidth,'.') + str(v).rjust(rightWidth))
# picnicItems = {'sandwiches':4,'apples':12,'cups':4,'cookies':8000}
# printPicnic(picnicItems,12,5)
# printPicnic(picnicItems,20,6)
# print(' hello '.strip())
# print(' hello '.lstrip())
# print(' hello '.rstrip())
# import pyperclip
# pyperclip.copy('Hello world!')
# print(pyperclip.paste())
#C:/Users/lenovo/AppData/Local/Programs/Python/Python36/python.exe
#**************************************************************************
#! python3
#p01.py - An insecure password locker program.
# PASSWORDS = {
# 'email':'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
# 'blog':'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
# 'luggage':'12345'
# }
# import sys,pyperclip
# if len(sys.argv) < 2:
# print('Usage: python pythonScript.py [account] - copy account password')
# sys.exit()
# account = sys.argv[1] #first command line arg is the account name
# if account in PASSWORDS:
# pyperclip.copy(PASSWORDS[account])
# print('Password for ' + ' copied to clipbord.')
# else:
# print('There is no account named ' + account)
"""
Lists of animals
Lists of aquarium life
Lists of biologists by author abbreviation
Lists of cultivars
"""
#******************************************************************************
#! python3
# bulletPointAdder.py - Adds Wikipedia bullet points to the start
# of each line of text on the clipboard
# import pyperclip
# text = pyperclip.paste()
# # TODO: Separate lines and add stars.
# lines = text.split('\n')
# for i in range(len(lines)):
# lines[i] = '* ' + lines[i]
# text = '\n'.join(lines)
# pyperclip.copy(text)
#******************************************************************************
#! python3
# tableData = [['apples','oranges','cherries','banana'],
# ['Alice','Bob','Carol','David'],
# ['dogs','cats','moose','goose']]
# def printTable(tableData):
# colWidths = [0]*len(tableData)
# for col in range(len(tableData)):
# for row in range(len(tableData[1])):
# if colWidths[col] <= len(tableData[col][row]):
# colWidths[col] = len(tableData[col][row])
# for col in range(len(tableData[0])):
# for row in range(len(tableData)):
# print(tableData[row][col].rjust(colWidths[row]+1),end='')
# print()
# printTable(tableData)
#******************************************************************************
#! python3
# def isPhoneNumber(text):
# if len(text) != 12:
# return False
# for i in range(0,3):
# if not text[i].isdecimal():
# return False
# if text[3] != '-':
# return False
# for i in range(4,7):
# if not text[i].isdecimal():
# return False
# if text[7] != '-':
# return False
# for i in range(8,12):
# if not text[i].isdecimal():
# return False
# return True
# # print(isPhoneNumber('415-555-4242'))
# # print(isPhoneNumber('415-555-424'))
# # print(isPhoneNumber('Moshi'))
# message = 'Call me at 415-555-4242 tomorrow.415-555-9999 is my office.'
# for i in range(len(message)):
# chunk = message[i:i+12]
# if isPhoneNumber(chunk):
# print('Phone number found: ' + chunk)
# print('Done')
#******************************************************************************
#! python3
# import re
# phoneNumberRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
# mo = phoneNumberRegex.search('My number is 415-555-4242')
# print(mo.group())
# phoneNumberRegex = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)')
# mo = phoneNumberRegex.search('My number is 415-555-4242')
# print(mo.group())
# print(mo.group(1))
# print(mo.group(2))
# print(mo.group(0))
# print(mo.groups())
# areaCode,mainNumber = mo.groups()
# print(areaCode,mainNumber)
# phoneNumberRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)')
# mo = phoneNumberRegex.search('My number is (415) 555-4242')
# print(mo.group())
# heroRegx = re.compile(r'Batman|Tina Fey')
# mo1 = heroRegx.search('Batman and Tina Fey.')
# print(mo1.group())
# mo2 = heroRegx.findall('Batman and Tina Fey.')
# print(mo2)
# batRegex = re.compile(r'Bat(man|mobile|copter|bat)')
# mo = batRegex.search('Batmobile lost a wheel')
# print(mo.group())
# heroRegx = re.compile(r'Bat(wo)?man')
# mo1 = heroRegx.search('Batwoman and Tina Fey.')
# print(mo1.group())
# phoneNumberRegex = re.compile(r'(\d\d\d-)?\d\d\d-\d\d\d\d')
# # mo1 = phoneNumberRegex.search('My number is 415-555-4242')
# # print(mo1.group())
# mo2 = phoneNumberRegex.search('My number is 555-4242')
# print(mo2.group())
# heroRegx = re.compile(r'Bat(wo)*man')
# mo1 = heroRegx.search('Batwoman and Tina Fey.')
# mo2 = heroRegx.search('The Adventures of Batwoman')
# mo3 = heroRegx.search('The Adventures of Batwowowowowoman')
# print(mo1.group())
# print(mo2.group())
# print(mo3.group())
# heroRegx = re.compile(r'Bat(wo)+man')
# mo1 = heroRegx.search('Batwoman and Tina Fey.')
# mo2 = heroRegx.search('The Adventures of Batwoman')
# mo3 = heroRegx.search('The Adventures of Batwowowowowoman')
# print(mo1.group())
# print(mo2.group())
# print(mo3.group())
# greedyRegex = re.compile(r'(ha){3,5}')
# mo1 = greedyRegex.search('hahahahaha')
# print(mo1.group())
# greedyRegex = re.compile(r'(ha){3,5}?')
# mo1 = greedyRegex.search('hahahahaha')
# print(mo1.group())
"""
\d :0-9的任何数字
\D :除0-9的数字以外的任何字符
\w :任何字母、数字或者下划线字符
\W :除字母、数字和下划线以外的任何字符
\s :空格、制表符或换行符
\S :除空格、制表符和换行符以外的任何字符
"""
# xmasRegex = re.compile(r'\d+\s\w+')
# print(xmasRegex.findall('1222 drummers,11 pipers,10 lords,9 ladies,8 maids,7 swans'))
# vowelRegex = re.compile(r'[aeiouAEIOU]')
# print(vowelRegex.findall('Robocop eats baby food.BABY FOOD.'))
# vowelRegex = re.compile(r'[^aeiouAEIOU]')
# print(vowelRegex.findall('Robocop eats baby food.BABY FOOD.'))
# vowelRegex = re.compile(r'[a-zA-Z0-9]')
# print(vowelRegex.findall('Robocop eats baby food.BABY FOOD. www.hao123.com'))
#***********************************************************************
"""
7.8 插入字符和美元字符
"""
# beginWithHelloRegex = re.compile(r'^Hello')
# print(beginWithHelloRegex.search('Hello World!'))
# print(beginWithHelloRegex.search('He said hello') == None)
# endWithNumber = re.compile(r'\d+$')
# print(endWithNumber.search('Your number is 42'))
# wholeStringIsNumber = re.compile(r'^\d+$')
# print(wholeStringIsNumber.search('34678235467235'))
# nameRegex = re.compile('First Name: (.*) Last Name: (.*)')
# mo = nameRegex.search('First Name: A1 Last Name: Sweigart')
# print(mo.group(1))
# print(mo.group(2))
# nongreedyRegex = re.compile('<.*?>')
# mo = nongreedyRegex.search('< To serve man > for dinner .>')
# print(mo.group())
# nongreedyRegex = re.compile('<.*>')
# mo = nongreedyRegex.search('< To serve man > for dinner .>')
# print(mo.group())
# nongreedyRegex = re.compile('<.*>',re.DOTALL)
# mo = nongreedyRegex.search('< To serve man > for dinner\ndgsdfsd .>')
# print(mo.group())
# namesRegex = re.compile(r'Agent \w+')
# print(namesRegex.sub('CENSORED','Agent Alice gave the secret documents to Agent Bob.'))
# namesRegex = re.compile(r'Agent (\w)\w*')
# print(namesRegex.sub(r'\1****','Agent Alice gave the secret documents to Agent Bob.'))
#*****************************************************************
# import re,pyperclip
#! Python3
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard
# phoneRegex = re.compile(r'''(
# (\d{3}|\(\d{3}\))? # area code
# (\s|-|\.)? # separator
# \d{3} # first 3 digits
# (\s|-|\.) # separator
# \d{4} # last 4 digits
# (\s*(ext|x|ext.)\s*\d{2,5})? # extension
# )
# ''',re.VERBOSE)
# mo = phoneRegex.search('415-222-4545 ext 22')
# print(mo.group())
# emailRegex = re.compile(r'''(
# [a-zA-Z0-9._%+-]+ # username
# @ # @ symbol
# [a-zA-Z0-9.-]+ # domain name
# (\.[a-zA-Z]{2,4}) # dot-something
# )
# ''',re.VERBOSE)
# mo1 = emailRegex.search('coyoko5@gmail.com')
# print(mo1.group())
# text = str(pyperclip.paste())
# matches = []
# for groups in phoneRegex.findall(text):
# matches.append(groups[0])
# for groups in emailRegex.findall(text):
# matches.append(groups[0])
# if len(matches) > 0:
# pyperclip.copy('\n'.join(matches))
# print('Copyed to clipbord: ')
# print('\n'.join(matches))
# else:
# print('No phone numbers or email addresses found.')
#*****************************************************************
import os
# print(os.path.join('user','bin','spam'))
myfiles = ['account.text','details.csv','invite.docx']
for filename in myfiles:
print(os.path.join('/user/asweigart',filename))
1254.93
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/coyoko/Python-Demo.git
git@gitee.com:coyoko/Python-Demo.git
coyoko
Python-Demo
Python Demo
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891