回复 10楼 wp231957
[em19谢谢版主。兄弟刚学这个东西没多久,很多地方不明白希望可以通过QQ或其他方式可以跟您取得联系啊。方便的话私信下您QQ号码可以吗?
程序代码:tempstr = input("挖普通土:")
if tempstr[-1:]=="方" :
print(tempstr[0:-1],"方")
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
print(tempstr[0:-2],"方")
else:
print("error")
tempstr = input("挖软土:")
if tempstr[-1:]=="方" :
print(tempstr[0:-1],"方")
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
print(tempstr[0:-2],"方")
else:
print("error")
tempstr = input("挖硬土:")
if tempstr[-1:]=="方" :
print(tempstr[0:-1],"方")
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
print(tempstr[0:-2],"方")
else:
print("error")
程序代码:
t1=t2=t3=0
tempstr = input("挖普通土:")
if tempstr[-1:]=="方" :
t1=int(tempstr[0:-1]) #确保是int类型输入 而不是浮点型输入
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
t1=int(tempstr[0:-2]) #确保是int类型输入 而不是浮点型输入
else:
print("error")
tempstr = input("挖软土:")
if tempstr[-1:]=="方" :
t2=int(tempstr[0:-1]) #确保是int类型输入 而不是浮点型输入
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
t2=int(tempstr[0:-2]) #确保是int类型输入 而不是浮点型输入
else:
print("error")
tempstr = input("挖硬土:")
if tempstr[-1:]=="方" :
t3=int(tempstr[0:-1]) #确保是int类型输入 而不是浮点型输入
elif tempstr[-2:]=="m3" or tempstr[-2:]=="M3" or tempstr[-2:]=="m3" :
t3=int(tempstr[0:-2]) #确保是int类型输入 而不是浮点型输入
else:
print("error")
print("总土方量: %d 方"%(t1+t2+t3))
'''
e:\>python ex3.py
挖普通土:12m3
挖软土:45方
挖硬土:56M3
总土方量: 113 方
e:\>
'''
