【Python Practice】Day 8- Question 22-25

'''
@Author: your name
@Date: 2020-07-13 18:21:52
@LastEditTime: 2020-07-13 21:48:41
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day8.py
'''

# Q22
# 读取终端输入的单词的数量,最后输出排序后的结果
def Q22():
    dic={}
    l=input().split()

    # 法1,使用dict
    # for i in l:
    #     dic[i]=dic.get(i,0)+1    # 获取key对应的value

    # words=dic.keys()   # dict_keys(['New', 'to', 'Python', 'or', 'choosing', 'between', '2', 'and', '3?', 'Read', '3.'])
    # print(words)
    # words=sorted(words)     # ['2', '3.', '3?', 'New', 'Python', 'Read', 'and', 'between', 'choosing', 'or', 'to']
    # print(words)

    # # print(sortwords)

    # for i in words:
    #     print("{}:{}".format(i,dic[i]))

    # 法2,使用set
    l_s=sorted(set(l))      # set 没有重复 得到一个[]
    print("ls:{}".format(l_s))
    for i in l_s:
        print("{}:{}".format(i,l.count(i)))


# Q23
# 计算平方值 p**n=p^n
def Q23():
    p=int(input())
    print("p:{}".format(p))
    print("{}^{}={}".format(p,2,p**2))

# Q 24
# 输出doc文件
def Q24():
    '''
    return p^n
    '''

    p=int(input())
    print("p:{}".format(p))
    print("{}^{}={}".format(p,2,p**2))

# Q 25
# 一个类,并实例化
class Car:
    name="car"

    def __init__(self,name=None):
        self.name=name

    




if __name__ == "__main__":
    # Q22()

    # Q23()

    # Q24
    # print(abs.__doc__)
    # print(Q24.__doc__)

    # Q25
    car1=Car("Honda")
    print("car1:{}".format(car1.name))

    car2=Car()
    car2.name="Toyota"
    print("car2:{}".format(car2.name))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tech沉思录

点赞加投币,感谢您的资瓷~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值