个人练习代码其一

# class InputOutString(object):
# #     def __init__(self):
# #         self.s = ""
# #
# #     def getString(self):
# #         print('请输入字符串:')
# #         self.s = input()
# #
# #     def printString(self):
# #         print(self.s.upper())
# #
# #
# # s = InputOutString()
# # s.getString()
# # s.printString()
# class preson:
#     def __init__(self,name):
#         self.name=name
#     def sayhi(self):
#         print('hello,my name is',self.name)
# p=preson('swroop')
# p.sayhi()
#
# class b:
#     def __init__(self):
#      pass
#"""使用isnstance()函数可以检测给定的对象是否属于或者继承于某个类或者类型
     #如
    #果是返回ture,否则返回false
#"""
# c=b()
# print(isinstance(c,b))
# class Man:
#
#     id=0# 类变量
#
#     def __init__(self, name):
#         self.name = name
#         self.id = self.id_number()
#
#     @classmethod   #类方法
#     def id_number(cls):
#        cls.id+=1
#
#        return cls.id
#
#
# a = Man('dfsdf')
# print(a.id)
# b = Man('fefw')
# print(b.id)
# a = input("请输入数字串:")
# len = a.__len__()
# # 末尾加个字符,但是len还是之前的len,这样可以防止处理之后越界
# a = a + 'Z'
# i = 0
# re = ""
# while( i < len):
#     temp = int(a[i]) * 10 + int(a[i+1])
#     # 连续两个无法连续
#     if(temp > 26):
#         re = re + chr(int(a[i]) + 65-1)
#         i+=1
#     else:
#         re = re + chr(temp + 65-1)
#         i+=2
# print(re)
#!/usr/bin/env/ python
# import math
# c,h,value=50,30,[]
# items=[x for x in input().split(',')]
# for d in items:
#     value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))
# print(','.join(value))

#
# print('请输入两个数字:')
# input_str = input()
# dimensions = [int(x) for x in input_str.split(',')]
# rowNum = dimensions[0]
# colNum = dimensions[1]
# multilist = [[0 for col in range(colNum)] for row in range(rowNum)]
# for row in range(rowNum):
#     for col in range(colNum):
#         multilist[row][col] = row * col
# print(multilist)

# ls=['中国','美国','日本']
# f=open('C:/Users/Administrator/Desktop/新建文本文档.txt','w')
# f.write('.'.join(ls))
# f.close()
# fo=open('C:/Users/Administrator/Desktop/新建文本文档.txt')
# ls=[]
# for line in fo:
#     line=line.replace("\n","")
#     ls.append(line.split(","))
# fo.close()
# ls=[[1,2],[3,4],[5,6]]
# for row in ls:
#     for column in row:
#         print(column)
#     print(row)
# l=[]
# for i in range(2000,3201):
#     if (i%7==0) and (i%5!=0):
#         l.append(str(i))
# print(','.join(l))
# def fact(x):
#     if x==0:
#         return 1
#     return x*fact(x-1)
# x=int(input('请输入一个数字:'))
# print(fact(x))
# n=int(input('请输入一个数字:'))
# d=dict()
# for i in range(1,n+1):
#     d[i]=i*i
# print(d)
# import re
# values=input('请输入一组数字:')
# l=values.split(',')
# k=re.findall(r'[0-9]+',values)
# t=tuple(k)
# print(k)
# print(t)
# class inputoutstrin(object):
#     def __init__(self):
#         self.s=""
#     def getString(self):
#         print("请输入字符串:")
#         self.s=input()
#     def printSrting(self):
#         print(("输出的字符串:"))
#         print(self.s.upper())
# strobj=inputoutstrin()
# strobj.getString()
# strobj.printSrting()
# import math
# c,h,value=50,30,[]
# items=input("请输入一组数字:")
# items=items.split(",")
# for d in items:
#     value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))
# print(','.join(value))
# input_str=input('请输入俩个数字:')
# dimensions=[int(x)  for  x  in input_str.split(',')]
# rowNum=dimensions[0]
# colNum=dimensions[1]
# multilist=[[0 for col in range(colNum)]for row in range(rowNum)]
# for row in range(rowNum):
#     for col in range(colNum):
#         multilist[row][col]=row*col
# print(multilist)
# items="without,hello,bag,world"
# print(items)
# print(type(items))
# print("输入一段单词列表:")
# items=[x for x in input().split(',')]
# items.sort()
# print (','.join(items))
# x = [4, 6, 2, 1, 7, 9]
# y = sorted(x)
# print(y)  # [1, 2, 4, 6, 7, 9]
# print(x)    # [4, 6, 2, 1, 7, 9]
# x=[4,6,2,1,7,9]
# x.sort()
# print(x)
# x = [4, 6, 2, 1, 7, 9]
# y = x[ : ]
# y.sort()
# print(y) # [1, 2, 4, 6, 7, 9]
# print(x)   # [4, 6, 2, 1, 7, 9]
# print (sorted('Python'))  #['P', 'h', 'n', 'o', 't', 'y']
#
#
# nums = [3, 2, 8 ,0 , 1]
# nums.sort(reverse=True)
# print(nums)#  降序排序 [8, 3, 2, 1, 0]
# nums.sort()
# print (nums)#  升序排序 [0, 1, 2, 3, 8]
#
# x = ['mmm', 'mm', 'mm', 'm' ]
# x.sort(key = len)
# print(x) # ['m', 'mm', 'mm', 'mmm']
#编写一个程序,接受逗号分隔的单词序列作为输入,
# 并在将句子中的所有字符大写后打印
# lines=[]
# print("请输入一段文字序列:")
# while True:
#     s=input()
#     if s:
#         lines.append(s.upper())
#     else:
#         break
# for esn in lines:
#     print(esn)
#接受一系列空格分隔的单词作为输入
# ,并在删除所有重复的单词并按字母数字排序后打印
# print('请输入一组字符串:')
# s=input()
# words=[word for word in s.split(' ')]
# print(" ".join(sorted(list(set(words)))))
#二进制转换十进制并判断输出能被五整除的数
# value=[]
# print("请输入逗号分隔的四位二进字数:")
# items=[x for x in input().split(',')]
# for p in items:
#     intp=int(p,2)
#     print(intp)
#     if not intp%5:
#         value.append(p)
# print(','.join(value))
# x = '1001'
# num = int(x,2)
# print(num)
#输出每个数字都为偶数的数字,逗号分隔
# values = []
# for i in range(1000, 3001):
#     s = str(i)
#     if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0) and (int(s[3])%2==0):
#         values.append(s)
# print (','.join(values))
#计算数字和空格的数量
# print("请输入:")
# s=input()
# digit=0
# alpha=0
# for c in s:
#     if c.isdigit():
#         digit=digit+1
#     elif c.isalpha():
#         alpha=alpha+1
#     else:
#         pass
# print("数字为:",digit)
# print("字母为:",alpha)
# a=input('请输入两个数字:')
# dimensions=[int(x)  for x in a.split(',')]
# rowNum=dimensions[0]
# colNum=dimensions[1]
# multlist=[[0 for col in range(colNum)] for row in range(rowNum)]
# for row in range(rowNum):
#     for col in range(colNum):
#         multlist[row][col]=row*col
# print(multlist)

# score = [[0]*3, [0]*3,[0]*3]
# print(score)



# myList = [([2] * 3) for i in range(4)]
# print(myList)
# myList = [([] * 3) for i in range(4)]
# print(myList)
# s=input("请输入:")
# upper=0
# lower=0
# for c in s:
#     if c.isupper():
#         upper+=1
#     elif c.islower():
#         lower+=1
#     else:
#         pass
# print("大写为:",upper)
# print("小写为:",lower)
# a=input("请输入一个数字:")
# n1=int("%s"%a)
# n2=int("%s%s"%(a,a))
# n3=int("%s%s%s"%(a,a,a))
# n4=int("%s%s%s%s"%(a,a,a,a))
# print(n1+n2+n3+n4)
"""values=input("输入:")
numbers=[x for x in values.split(",") if int(x)%2!=0]
print(",".join(numbers))"""
"""列表推导对列表中的每个偶数进行输出"""
# netAmount = 0
# print("请输入:")
# while True:
#     s = input()
#     if not s:
#         break
#     values = s.split(" ")
#     operation = values[0]
#     amount = int(values[1])
#     if operation=="D":
#         netAmount+=amount
#     elif operation=="W":
#         netAmount-=amount
#     else:
#         pass
# print ("结果为:",netAmount)
# import re
# value=[]
# print("请输入:")
# items=[x for x in input().split(",")]
# for p in items:
#     if len(p)<6 or len(p)>12:
#         continue
#     else:
#         pass
#     if not re.search("[a-z]",p):
#         continue
#     elif not re.search("[0-9]",p):
#         continue
#     elif not re.search("[A-Z]",p):
#         continue
#     elif not re.search("[$#@]",p):
#         continue
#     elif re.search("\n",p):
#         continue
#     else:
#         pass
#     value.append(p)
# print(",".join(value))
"""
利用re模块进行检查密码的有效性
"""
#from operator import itemgetter
# l=[]
# print("请输入:")
# while True:
#     s=input()
#     if not s:
#         break
#     l.append(tuple(s.split(",")))
# print(sorted(l))
# from operator import itemgetter, attrgetter
#
# # ----A-------B---C----D---
# data = [
#     ('老王', 18, 175, 75),
#     ('阿汤哥', 15, 165, 70),
#     ('罗宾森', 23, 180, 100),
#     ('小风', 10, 171, 60),
#     ('黄佬', 20, 175, 65),
# ]
#
# """itemgetter,它构建的函数会返回提取的值构成的元组"""
# get_c_d = itemgetter(2, 3)
# for value in data:
#     print(get_c_d(value))
# print("-------------------------------------")
# # 表示根据 C,D 来进行排序
# for value in sorted(data, key=itemgetter(2, 3)):
#     print(value)
# print("-------------------------------------")
#
# from collections import namedtuple
#
# size = namedtuple('size', 'height weight')
# stu = namedtuple('stu', 'name age size')
# data_stu = [stu(name, age, size(height, weight)) for name, age, height, weight in data]
#
"""用attrgetter来处理 主要用于嵌套的东西吧"""
# get_name_age = attrgetter('name', 'size.height')
#
# for value in sorted(data_stu, key=attrgetter('size.height')):
#     print(get_name_age(value))
# print("-------------------------------------")
# def putNumbers(n):
#     i=0
#     while i<n:
#         j=i
#         i+=1
#         if j%7==0:
#             yield j
# for i in putNumbers(100):
#     print(i)
"""
利用生成器迭代输出7的整数"""
# mylist = [x*x for x in range(3)]
# for i in mylist :
#     print(i)
"""
可迭代对象"""
# l=[]
# print("输入:")
# while True:
#     s=input()
#     if not s:
#         break
#     l.append(tuple(s.split(",")))
# print(sorted(l))
# def putNumbers(n):
#     i=0
#     while i<n:
#         j=i
#         i=i+1
#         if j%7==0:
#             yield j
# for i in putNumbers(100):
#     print(i)
"""
为控制台输入计算机器人移动之后距离开始位置的距离
"""
# import math
# pos=[0,0]
# print("输入:")
# while True:
#     s=input()
#     if not s:
#         break
#     movement=s.split(" ")
#     direction=movement[0]
#     steps=int(movement[1])
#     if direction=="UP":
#         pos[0]+=steps
#     elif direction=="DOWN":
#         pos[0]-=steps
#     elif direction=="LEFT":
#         pos[1]-=steps
#     elif direction=="RIGHT":
#         pos[1]+=steps
#     else:
#         pass
# print(int(round(math.sqrt(pos[1]**2+pos[0]**2))))
"""
编写一个程序来计算输入中单词的频率 ,按字母顺序对键进行排序后输出
"""
# freq={}
# print("请输入:")
# line=input()
# for word in line.split():
#     freq[word]=freq.get(word,0)+1
# words=sorted(freq.keys())
# for w in words:
#     print("%s:%d"%(w,freq[w]))
"""
可以计算数字平方值的方法
"""
# def square(num):
#     return num**2
# print(square(2))
# print(square(3))
"""
输出打印内置函数文档"""
# print(abs.__doc__)
# print(int.__doc__)
# print(input.__doc__)
"""
非内置函数"""
# def square(num):
#     return  num**2
# print(square(2))
# print(square.__doc__)
# class Person:
#     name="Person"
# def __init__(self,name=None):
#     self.name=name
# jeffrey=Person()
# jeffrey.name="jeffrey"
# print("%s name is %s"%(Person.name,jeffrey.name))
# nico=Person()
# nico.name="Nico"
# print("%s1 name is %s "%(Person.name,nico.name))
"""
定义一个类,它具有‘类参数’并具有相同的实例参数
首先定义一个实例参数,需要在__int__方法中添加它。您可以使用构造参数
初始化对象,也可以稍后设置
"""
# import os
# import time
# os.path.abspath("C:/Users/Administrator/Desktop/main.txt")
# os.path.dirname("C:/Users/Administrator/Desktop/main.txt")
# time.ctime(os.path.getctime("C:/Users/Administrator/Desktop/main.txt"))


# import os
# os.system("C:\\windows\\System32\\calc.exe")
"""
打开电脑内置计算器::
将计算器的文件路径作为参数放到os.system函数中"""
# import os
# libs={"pefile"}
# try:
#     for lib in libs:
#         os.system("pip.exe install " + lib)
#     print("successful")
# except:
#     print("failed somehow")
"""
第三方库自动安装脚本
"""
# n=int(input())
# c=n%2
# print(c)
# import sys
# sys.path.append("altgraph")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值