python简易图形计算器

本人高中菜鸟一枚,做这个完全是出于兴趣,如果有可改进之处,希望各位大佬多多指教

源码如下

"""
中文源码
名称:图形计算器.py
日期:2020.8.3
作者:li131464
"""
print("声明:计算过程一律使用厘米制(cm)")
#提前对pi赋值
p = 3.14
xdi = input("请选择计算类型1:面积,2:体积:")
print(type(xdi))
idx = int(xdi)
if idx == 1:
       xi = input("请选择计算对象1:正方形,2:长方形,3圆形,4梯形:")
       print(type(xi))
       ix = int(xi)
       if ix == 1:
              a = input("请输入边长:")
              aint = int(a)*int(a)
              print("这个正方形的面积是:",aint,"cm^2")
              print("本次计算完成,谢谢!")
       elif ix == 2:
              a = input("请输入边长:")
              b = input("请输入另一边长:")
              aint = int(a)*int(b)
              print("这个长方形的面积是:",aint,"cm^2")
              print("本次计算完成,谢谢!")
       elif ix == 3:
              a = input("请输入圆半径:")
              aint = p*int(a)**2
              print("这个圆的面积是:",aint,"cm^2")
              print("本次计算完成,谢谢!")
       elif ix == 4:
              a = input("请输入梯形底边长:")
              b = input("请输入梯形另一底边长:")
              c = input("请输入梯形高:")
              aint = (int(a)+int(b))*int(c)/2
              print("这个梯形的面积是:",aint,"cm^2")
              print("本次计算完成,谢谢!")
       else:
              print("很抱歉,您输入的选项暂时没有")
elif idx == 2:
       xi = input("请选择计算对象1:正方体,2:长方体,3圆:")
       print(type(xi))
       ix = int(xi)
       if ix == 1:
              a = input("请输入正方体边长:")
              aint = int(a)**3
              print("这个正方体的体积是:",aint,"cm^3")
              print("本次计算完成,谢谢!")
       elif ix == 2:
              a = input("请输入长方体长:")
              b = input("请输入长方体宽:")
              a = input("请输入长方体长:")
              aint = int(a)*int(b)*int(c)
              print("这个长方体的体积是:",aint,"cm^3")
              print("本次计算完成,谢谢!")
       elif ix == 3:
              xz = input("请选择圆的具体类型1:圆球,2:圆柱,3:圆锥,4:圆台:")
              print(type(xz))
              zx = int(xz)
              if zx == 1:
                     a = input("请输入圆球的半径:")
                     aint = (3/4)*p*int(a)**3
                     print("这个圆球的体积是:",aint,"cm^3")
                     print("本次计算完成,谢谢!")
              elif zx == 2:
                     a = input("请输入圆柱的底面圆半径:")
                     b = input("请输入圆球的高:")
                     aint = int(b)*p*int(a)**2
                     print("这个圆柱的体积是:",aint,"cm^3")
                     print("本次计算完成,谢谢!")
              elif zx == 3:
                     a = input("请输入圆锥的底面圆半径:")
                     b = input("请输入圆锥的高:")
                     aint = int(b)*(1/3)*p*int(a)**2
                     print("这个圆锥的体积是:",aint,"cm^3")
                     print("本次计算完成,谢谢!")
              elif zx == 4:
                     a = input("请输入圆台一底面圆半径:")
                     b = input("请输入圆台另一底面圆半径:")
                     c = input("请输入圆台的高:")
                     aint = (1/3)*p*int(c)*(int(a)**2+int(b)**2+int(a)*int(b))
                     print("这个圆台的体积是:",aint,"cm^3")
                     print("本次计算完成,谢谢!")
                     
              else:
                   print("很抱歉,您输入的选项暂时没有")
else:
       print("很抱歉,您输入的选项暂时没有")
"""
English source code
name:Simple graphic calculator.py
date:2020.8.3
Author:li131464
"""
print("Statement: all calculations are in centimeter system(cm)")
p = 3.14
xdi = input("Please select calculation type 1: area, 2: volume:")
print(type(xdi))
idx = int(xdi)
if idx == 1:
       xi = input("Please select 1: square, 2: rectangle, 3 circle, 4 trapezoid:")
       print(type(xi))
       ix = int(xi)
       if ix == 1:
              a = input("Please input side length:")
              aint = int(a)*int(a)
              print("The area of this square is:",aint,"cm^2")
              print("This calculation is completed. Thank you!")
       elif ix == 2:
              a = input("Please input side length:")
              b = input("Please enter the length of the other side:")
              aint = int(a)*int(b)
              print("The area of this rectangle is:",aint,"cm^2")
              print("This calculation is completed. Thank you!")
       elif ix == 3:
              a = input("Please enter circle radius:")
              aint = p*int(a)**2
              print("The area of this circle is:",aint,"cm^2")
              print("This calculation is completed. Thank you!")
       elif ix == 4:
              a = input("Please input trapezoid bottom length:")
              b = input("Please input the length of the other bottom side of trapezoid:")
              c = input("Please input trapezoid height:")
              aint = (int(a)+int(b))*int(c)/2
              print("The area of this trapezoid is:",aint,"cm^2")
              print("This calculation is completed. Thank you!")
       else:
              print("Sorry, the options you entered are not available")
elif idx == 2:
       xi = input("Please select the calculation object 1: cube, 2: box, 3 circle:")
       print(type(xi))
       ix = int(xi)
       if ix == 1:
              a = input("Please input the side length of cube:")
              aint = int(a)**3
              print("The volume of this cube is:",aint,"cm^3")
              print("This calculation is completed. Thank you!")
       elif ix == 2:
              a = input("Please input the length of the box:")
              b = input("Please input the width of the box:")
              a = input("Please input the length of the box:")
              aint = int(a)*int(b)*int(c)
              print("The volume of this box is:",aint,"cm^3")
              print("This calculation is completed. Thank you!")
       elif ix == 3:
              xz = input("Please select the specific type of circle: 1: ball, 2: cylinder, 3: cone, 4: cone:")
              print(type(xz))
              zx = int(xz)
              if zx == 1:
                     a = input("Please enter the radius of the ball:")
                     aint = (3/4)*p*int(a)**3
                     print("The volume of this sphere is:",aint,"cm^3")
                     print("This calculation is completed. Thank you!")
              elif zx == 2:
                     a = input("Please enter the radius of the bottom circle of the cylinder:")
                     b = input("Please enter the height of the ball:")
                     aint = int(b)*p*int(a)**2
                     print("The volume of this cylinder is:",aint,"cm^3")
                     print("This calculation is completed. Thank you!")
              elif zx == 3:
                     a = input("Please enter the radius of the base circle of the cone:")
                     b = input("Please enter the height of the cone:")
                     aint = int(b)*(1/3)*p*int(a)**2
                     print("The volume of this cone is :",aint,"cm^3")
                     print("This calculation is completed. Thank you!")
              elif zx == 4:
                     a = input("Please enter the radius of the bottom of the cone:")
                     b = input("Please enter the radius of the other bottom of the cone:")
                     c = input("Please enter the height of the cone:")
                     aint = (1/3)*p*int(c)*(int(a)**2+int(b)**2+int(a)*int(b))
                     print("The volume of this cone is:",aint,"cm^3")
                     print("This calculation is completed. Thank you!")
                     
              else:
                     print("Sorry, the options you entered are not available") 
                     
else:
       print("Sorry, the options you entered are not available")              

猜你喜欢

转载自blog.csdn.net/lkj753/article/details/107771632