python编程练习第2个题目

题目:火星数字
我的代码:


a = [1,2,3,4,5,6,7,8,9,10,11,12]
b = ['jan','feb','mar','apr','may','jun','jly','aug','sep','oct','nov','dec']
c = ['tam','hel','maa','huh','tou','kes','hei','elo','syy','lok','mer','jou']
#火星数字转地球数字
m = input('请输入要转换的火星数字')
m1 = m.split(' ')
if len(m1) == 1:
    for i in range(12):
        if b[i] == m1[0]:
            print(a[i])
            break
if len(m1) == 2:
    j = 0
    for i in range(12):
        if c[i] == m1[0]:
            j += a[i]*13
            break
    for i in range(12):
        if b[i] == m1[1]:
            j += a[i]
            break
    print(j)

#地球数字转火星数字
n = int(input('请输入要转换的地球数字'))
z1 = n % 13  #低位
z2 = n // 13 #高位
#python中的整除是//
if z2 == 0:
    print(b[z1-1])
else:
    print(c[z2-1],b[z1-1])

你可能感兴趣的:(python编程练习第2个题目)