python_ex1基本语法

python_ex1基本语法

inputtemp = input()                          # 获取输入字符串
if inputtemp[-1] in ['F','f']:               # 最后一个输入字符是F/f    if后有:
    Ctemp = (eval(inputtemp[0:-1])-32)/1.8   
    print("{:.2f}C".format(Ctemp))           # 输出保留小数后两位,(:.2f)
elif inputtemp[-1] in ['C','c']:
    Ftemp = eval(inputtemp[0:-1])*1.8+32
    print("{:.2f}F".format(Ftemp))
else:
    print("输入格式错误")

 

 

 

python_ex1基本语法 

num = input()       
Cnum =""                 # 转换后的字符串存储在Cnum
for n in num:
    if n == '0':
        Cnum = Cnum + '零'
    elif n == '1':
        Cnum = Cnum + '一'
    elif n == '2':
        Cnum = Cnum + '二'
    elif n == '3':
        Cnum = Cnum + '三'
    elif n == '4':
        Cnum = Cnum + '四'
    elif n == '5':
        Cnum = Cnum + '五'
    elif n == '6':
        Cnum = Cnum + '六'
    elif n == '7':
        Cnum = Cnum + '七'
    elif n == '8':
        Cnum = Cnum + '八'
    elif n == '9':
        Cnum = Cnum + '九'
print(Cnum)

 

 python_ex1基本语法

 

intemp = input()
intemp = intemp + ' '   # 索引不包括最右边索引值
if intemp[0] == 'C':
    Ftemp = eval(intemp[1:-1])*1.8+32
    print("F{:.2f}".format(Ftemp))
elif intemp[0] == 'F':
    Ctemp = (eval(intemp[1:-1])-32)/1.8
    print("C{:.2f}".format(Ctemp))
    

 

python_ex1基本语法

invalue = input()
invalue = invalue +' '
if invalue[0:3] == "RMB":
    Uvalue = eval(invalue[3:-1])/6.78
    print("USD{:.2f}".format(Uvalue))
elif invalue[0:3] == "USD":
    Rvalue = eval(invalue[3:-1])*6.78
    print("RMB{:.2f}".format(Rvalue))

 

上一篇:CF840A Leha and Function


下一篇:斯坦福机器学习by吴恩达-线性回归 python实现(ex1更新,含3D画图)