Python字符串练习1
一、字符串截取
print("故宫长城")
二、判断回文字符串
s = input()
rs = list(reversed(s))
print(s)
if list(s) == rs:
print("Yes")
else:
print("No")
三、字符串逆序
x = input("")
c = x[::-1]
print(c)
四、三角形面积
import math
a = eval(input())
b = eval(input())
c = eval(input())
p = (a+b+c)/2.0
s = math.sqrt(p*(p-a)*(p-b)*(p-c))
print("%.2f" % s)
五、圆的周长与面积
import math
r = eval(input())
t = 2*r*3.14159
s = 3.14159*r*r
print("%.4f " % t, end="")
print("%.4f " % s)
六、节约用电
x = eval(input())
if x < 0:
print("Invalid Value!")
elif x <= 50:
ans = x*0.53
print("cost = %.2f" % ans)
else:
ans = 50*0.53+(x-50)*0.58
print("cost = %.2f" % ans)
七、温度转换
x = input()
a = x[0]
b = eval(x[1:])
if a == 'C':
s = (b*1.8)+32
print("F%.2f" % s)
else:
s = (b - 32) / 1.8
print("C%.2f" % s)
|