首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

PTA-浙大版《Python 程序设计》AC解答汇总-第二章

  • 24-03-02 23:55
  • 3725
  • 7839
blog.csdn.net
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
# 第2章-1 计算 11+12+13+...+m (30分)
def demo_2_1():
    print ("sum =",sum(list(range(11,int(input())+1))))


# 第2章-2 计算分段函数[1] (10分)
def demo_2_2():
    x=float(input())
    res=0
    if x!=0:res= 1./x
    print("f(%.1f) = %.1f"%(x,res))


# 第2章-3 阶梯电价 (15分)
def demo_2_3():
    x=float(input())
    res=0
    if x<0:
        print("Invalid Value!")
    elif x<=50:
        res = x*0.53
        print("cost = %.2f"%res)
    else:
        res = 50*0.53+(x-50)*0.58
        print("cost = %.2f"%res)


# 第2章-4 特殊a串数列求和 (20分)
def demo_2_4():
    a,n=input().split()
    print("s = %d"%sum([int(a*i) for i in range(1,int(n)+1)]))


# 第2章-5 求奇数分之一序列前N项和 (15分)
def demo_2_5():
    print("sum = %.6f"%sum([ 1./(2*x-1) for x in range(1,int(input())+1)]))


# 第2章-6 求交错序列前N项和 (15分)
def demo_2_6():
    print("%.3f"%sum([i/(2*i-1) if i%2==1 else -i/(2*i-1) for i in range(1,int(input())+1)]))


# 第2章-7 产生每位数字相同的n位数 (30分)
def demo_2_7():
    a,b=input().split(",")
    print(a.strip()*int(b))


# 第2章-8 转换函数使用 (30分)
def demo_2_8():
    a,b=input().split(",")
    print(int(a,int(b)))


# 第2章-9 比较大小 (10分)
def demo_2_9():
    print(*sorted(map(int,input().split())),sep="->")


# 第2章-10 输出华氏-摄氏温度转换表 (15分)
def demo_2_10():
    lower,upper=map(int,input().split())
    if lower>upper or upper>100:
        print("Invalid.")
    else:
        print("fahr celsius")
        for i in range(lower,upper+1,2):
            print("{:d}{:>6.1f}".format(i,5*(i-32)/9))


# 第2章-11 求平方与倒数序列的部分和 (15分)
def demo_2_11():
    m,n=map(int,input().split())
    print("sum = %.6f"%sum([float(x*x+1./x) for x in range(m,n+1)]))


# 第2章-12 输出三角形面积和周长 (15分)
def demo_2_12():
    import numpy as np
    a,b,c=map(int,input().split())
    s=(a+b+c)/2
    a2=s*(s-a)*(s-b)*(s-c)
    if a2>0:
        print("area = %.2f; perimeter = %.2f"%(np.sqrt(a2),(a+b+c)))
    else:
        print("These sides do not correspond to a valid triangle")


# 第2章-13 分段计算居民水费 (10分)
def demo_2_13():
    x=int(input())
    y=0
    if x<=15:
        y=4.*x/3
    else:
        y=2.5*x-17.5
    print("%.2f"%y)
        

# 第2章-14 求整数段和 (15分)
def demo_2_14():
    a,b=map(int,input().split())
    cnt,res=0,0
    for i in range(a,b+1):
        print("{:>5}".format(i),end="")
        res=res+i
        cnt=cnt+1
        if cnt%5==0 and i!=b:print("\n",end="")
    print("\nSum = %d"%res)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
注:本文转载自blog.csdn.net的邂逅模拟卷的文章"https://blog.csdn.net/qq_34451909/article/details/107928538"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top