【Python Practice】Day 15 Question 54-59(正则+编码转换)

'''
@Author: your name
@Date: 2020-07-21 09:51:06
@LastEditTime: 2020-07-21 10:15:50
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day15.py
'''
# -*- coding: utf-8 -*-   # Q58

import re 

# Question 54
# 读取邮箱地址中的公司名称
def Q54():
    email = "john@google.com elise@python.com"
    pattern = "(\w+)@(\w+).com"     # 正则,带括号的是要输出的内容
    ans=re.findall(pattern, email)
    print(ans)

# Question 55
# 读取输入中的数字
def Q55():
    r=input()
    # print(r)
    pattern="\d"
    ans=re.findall(pattern,r)
    print(ans)

# Question 56
# Print a unicode string "hello world".
def Q56():
    uHello=u"Hello,World!"   # Use u'strings' format to define unicode string.
    print(uHello)

# Question 57
# 读取ascii码转变为utf-8  
def Q57():
    s=input()
    u=s.encode('utf-8')   # Use unicode()/encode() function to convert.
    print(u)


# Question 58
# Write a special comment to indicate a Python source code file is in unicode.
# 见文件开始

# Question 59
# 计算1/2+2/3+3/4+...+n/n+1 
def Q59():
    n=int(input("n="))
    sum=0
    for i in range(1,n+1):
        sum+=float(i)/float(i+1)

    print(round(sum,2))             # round 保留两位小数


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

    # Q55()

    # Q56()

    # Q57()

    Q59()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Tech沉思录

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

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

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

打赏作者

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

抵扣说明:

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

余额充值