Homework Day04

Homework Day04

def getPentagonalNumber(n):
    if n % 10 == 0:
        print()

def Start():
    for n in range(1,101):
        a = n * (3 * n - 1) / 2
        print("%d"%a,end = "\t")
        getPentagonalNumber(n)
Start()

Homework Day04

 def sumDigits(n):
    sum = 0
    m = str(n)
    for i in range(len(m)):
        num = n//10**i%10
        sum += num 
    print(sum)
def start():
    n = int(input("输入一个整数:"))
    sumDigits(n)
start()

Homework Day04
def displaySortedNumbers(num1,num2,num3):
c = [num1,num2,num3]
c.sort()
print©

def Start():
num1,num2,num3 = map(int,input(‘请输入三个数(,分隔)’).split(’,’))
displaySortedNumbers(num1,num2,num3)
Start()
Homework Day04

 def dutureInvestmentValue(investmentAmount,monthlyInterestRate,years):
    for i in range(1,years+1):
        j = investmentAmount * monthlyInterestRate*0.01
        investmentAmount += j
        print(i,end = "\t")
        print("%.2f"%investmentAmount)

def Start():
    investmentAmount = int(input("请输入投资金额:"))
    monthlyInterestRate = int(input("请输入年利率(百分比格式):"))
    print("Years  Future Value")
    years = 30
    dutureInvestmentValue(investmentAmount,monthlyInterestRate,years)
Start() 

Homework Day04

 def printChars(ch1,ch2,numberPerLine):
    for i in range(ch1,ch2+1):
        j = chr(i)
        print(j,end = " ")
        if (i + 2) % 10 == 0:
            print()

def Start():
    ch1 = 49
    ch2 = 90
    numberPerLine = 1
    printChars(ch1,ch2,numberPerLine)
Start()

Homework Day04

def numberOfDaysInAYear(year):
    for i in range(year,year + 11):
        print("%d年"%i,end = "  ")
        if i % 4 == 0:
            print("366天")
        else:
            print("365天")

def Start():
    year = 2010
    numberOfDaysInAYear(year)
Start()

Homework Day04

import math
def distance(x1,x2,y1,y2):
    mo = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    print("两点间的距离是%.2f"%mo)
def Start():
    x1,x2 = map(float,input('输入x点的坐标(逗号分隔):').split(','))
    y1,y2 = map(float,input('输入y点的坐标(逗号分隔):').split(','))
    distance(x1,x2,y1,y2)
Start()

Homework Day04

def sushu(p):
    i = 2
    c = []
    d = []
    while i <= p:
        j = 2
        while j <= i:
            if i % j == 0:
                if i == j:
                    c.append(i)
                break
            j += 1
        i += 1
    print(c)
    for p in c:
        d.append(2 ** (p-1))
    print(d)
def Start():
    p = 31
    sushu(p)
Start()

Homework Day04
Homework Day04

import random
def zhi(a,b):
    c = a + b
    if a == 2 or a == 2 or a == 13:
        print("很遗憾,你输了")
    elif a == 7 or a == 11:
        print("恭喜你,你赢了")
    else:
        bi()
def bi():
    f = random.randint(1,7)
    d = random.randint(1,7)
    print(f)
    print(d)
    e = f + d
    if e == 7:
        print("很遗憾,你输了")
    elif e == c:
        print("恭喜你,你赢了")
    else:
        bi()
def Start():
    a = random.randint(1,7)
    b = random.randint(1,7)
    print(a)
    print(b)
    zhi(a,b)
Start()

Homework Day04
Homework Day04
Homework Day04
Homework Day04
Homework Day04

上一篇:Python_HomeWork_Day01_1


下一篇:Spring框架学习(八):@Qualifier实现高级装配