Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在期末显示总折旧值?_Python_Python 3.x - Fatal编程技术网

Python 如何在期末显示总折旧值?

Python 如何在期末显示总折旧值?,python,python-3.x,Python,Python 3.x,我如何显示最后加在一起的所有折旧值?这是去年唯一的一部。此外,如果还有什么我可以添加到我的代码,我将感谢任何建议 # Constants to use for deciding large or small apartment LARGE = 0.10 SMALL = 0.08 # inputs for getting user information try: #data validation cost = float(input("Enter how much the house i

我如何显示最后加在一起的所有折旧值?这是去年唯一的一部。此外,如果还有什么我可以添加到我的代码,我将感谢任何建议

# Constants to use for deciding large or small apartment
LARGE = 0.10
SMALL = 0.08
# inputs for getting user information
try: #data validation
    cost = float(input("Enter how much the house is worth:\n "))
except:
    print("Please enter a number. Restart program")
    exit()
size = (input("How big is your apartment? (Large or Small):\n ")).upper()
years = int(input("How long is the schedule? (Years):\n "))
# Rate selection
if size == 'Large' or 'large':
    rate = LARGE
if size == 'Small' or 'small' :
    rate = SMALL

# Header for the table
print(f'\n{"Year":>10}{"Current value":>15}{"Depreciated value":>25}{"Depreciation":>15}')

# Calculate the results for each year and show the user
for year in range(1, years+1):
    value = cost * rate
    aptcost = cost - value
    print(f'{year:<4} {cost:>15.2f} {aptcost :25.2f} {value:15.2f}')
    cost = aptcost

    # Display the results to the user
print(f'\n\nDepreciation rate is: {rate:.2f}')
print(f'Total depreciation upon end of schedule: ${aptcost:.2f}')
#用于决定大小公寓的常数
大=0.10
小=0.08
#获取用户信息的输入
try:#数据验证
成本=浮动(输入(“输入房屋价值:\n”))
除:
打印(“请输入一个数字。重新启动程序”)
退出()
size=(输入(“您的公寓有多大?(大或小):\n”)。upper()
years=int(输入(“计划有多长?(年):\n”))
#费率选择
如果大小==“大”或“大”:
比率=大
如果大小==“小”或“小”:
比率=小
#表的标题
打印(f'\n{“年”:>10}{“当前值”:>15}{“折旧值”:>25}{“折旧”:>15}')
#计算每年的结果并向用户显示
对于范围内的年份(1年+1年):
价值=成本*费率
aptcost=成本-价值
打印(f'{年份:15.2f}{aptcost:25.2f}{值:15.2f}')
成本=aptcost
#向用户显示结果
打印(f'\n\n沉积速率为:{rate:.2f}')
打印(f'计划结束时的总折旧:${aptcost:.2f}')

不确定这是否是您想要做的,但总折旧是用户输入的成本减去for循环结束时的aptcost。所以可能是这样的:

original_cost = cost
for year in range(1, years+1):
     value = cost * rate
     aptcost = cost - value
     print(f'{year:<4} {cost:>15.2f} {aptcost :25.2f} {value:15.2f}')
     cost = aptcost

# Display the results to the user
print(f'\n\nDepreciation rate is: {rate:.2f}')
print(f'Total depreciation upon end of schedule: ${original_cost-aptcost:.2f}')
原始成本=成本 对于范围内的年份(1年+1年): 价值=成本*费率 aptcost=成本-价值 打印(f'{年份:15.2f}{aptcost:25.2f}{值:15.2f}') 成本=aptcost #向用户显示结果 打印(f'\n\n沉积速率为:{rate:.2f}') 打印(f'计划结束时的总折旧:${original_cost-aptcost:.2f}')
希望能有帮助

不确定这是否是您想要做的,但总折旧是用户输入的成本减去for循环结束时的aptcost。所以可能是这样的:

original_cost = cost
for year in range(1, years+1):
     value = cost * rate
     aptcost = cost - value
     print(f'{year:<4} {cost:>15.2f} {aptcost :25.2f} {value:15.2f}')
     cost = aptcost

# Display the results to the user
print(f'\n\nDepreciation rate is: {rate:.2f}')
print(f'Total depreciation upon end of schedule: ${original_cost-aptcost:.2f}')
# Constants to use for deciding large or small apartment
LARGE = 0.10
SMALL = 0.08
# inputs for getting user information
'''
   Instead of restarting the entire program just loop until a valid value is entered
   Including all input into 1 loop is not ideal as an error will force the user to start from the beginning again, 
   you can split every input into its own loop to imporove the experience
'''
while True:
    try:
        cost = float(input("Enter how much the house is worth:\n "))
        size = (input("How big is your apartment? (Large or Small):\n ")).upper()
        if size not in ['LARGE','SMALL']:
            print("Please enter a valid size: Large or Small")
            continue
        years = int(input("How long is the schedule? (Years):\n "))
    except ValueError: # Call Value Error, don`t leave your except open
        print("Please enter a valid value")
    else:
        # Rate selection
        if size == 'LARGE': rate = LARGE
        else: rate = SMALL
        break # Break loop if no value validation errors occurred

# Header for the table
print(f'\n{"Year":>10}{"Current value":>15}{"Depreciated value":>25}{"Depreciation":>15}')

# Calculate the results for each year and show the user
initial_cost = cost
total_depreciation = 0
for year in range(years):
    depreciation_value = cost * rate
    depreciation_cost = cost - depreciation_value
    total_depreciation += depreciation_value
    print(f'{year+1:<4} {cost:>15.2f} {depreciation_cost :25.2f} {depreciation_value :15.2f}')
    cost = depreciation_cost

    # Display the results to the user
print(f'\n\nDepreciation rate is: {rate:.2f}')
print(f'Total depreciation upon end of schedule: ${total_depreciation:.2f}')
原始成本=成本 对于范围内的年份(1年+1年): 价值=成本*费率 aptcost=成本-价值 打印(f'{年份:15.2f}{aptcost:25.2f}{值:15.2f}') 成本=aptcost #向用户显示结果 打印(f'\n\n沉积速率为:{rate:.2f}') 打印(f'计划结束时的总折旧:${original_cost-aptcost:.2f}') 希望能有帮助

#用于决定大小公寓的常数
# Constants to use for deciding large or small apartment
LARGE = 0.10
SMALL = 0.08
# inputs for getting user information
'''
   Instead of restarting the entire program just loop until a valid value is entered
   Including all input into 1 loop is not ideal as an error will force the user to start from the beginning again, 
   you can split every input into its own loop to imporove the experience
'''
while True:
    try:
        cost = float(input("Enter how much the house is worth:\n "))
        size = (input("How big is your apartment? (Large or Small):\n ")).upper()
        if size not in ['LARGE','SMALL']:
            print("Please enter a valid size: Large or Small")
            continue
        years = int(input("How long is the schedule? (Years):\n "))
    except ValueError: # Call Value Error, don`t leave your except open
        print("Please enter a valid value")
    else:
        # Rate selection
        if size == 'LARGE': rate = LARGE
        else: rate = SMALL
        break # Break loop if no value validation errors occurred

# Header for the table
print(f'\n{"Year":>10}{"Current value":>15}{"Depreciated value":>25}{"Depreciation":>15}')

# Calculate the results for each year and show the user
initial_cost = cost
total_depreciation = 0
for year in range(years):
    depreciation_value = cost * rate
    depreciation_cost = cost - depreciation_value
    total_depreciation += depreciation_value
    print(f'{year+1:<4} {cost:>15.2f} {depreciation_cost :25.2f} {depreciation_value :15.2f}')
    cost = depreciation_cost

    # Display the results to the user
print(f'\n\nDepreciation rate is: {rate:.2f}')
print(f'Total depreciation upon end of schedule: ${total_depreciation:.2f}')
大=0.10 小=0.08 #获取用户信息的输入 ''' 只需循环直到输入有效值,而不是重新启动整个程序 将所有输入包含在1个循环中并不理想,因为错误会迫使用户重新开始, 您可以将每个输入拆分为自己的循环,以提升体验 ''' 尽管如此: 尝试: 成本=浮动(输入(“输入房屋价值:\n”)) size=(输入(“您的公寓有多大?(大或小):\n”)。upper() 如果大小不在[‘大’、‘小’]: 打印(“请输入有效尺寸:大或小”) 持续 years=int(输入(“计划有多长?(年):\n”)) Exception ValueError:#调用值错误,不要让Exception打开 打印(“请输入有效值”) 其他: #费率选择 如果大小=‘大’:比率=大 其他:费率=小 中断#如果未发生值验证错误,则中断循环 #表的标题 打印(f'\n{“年”:>10}{“当前值”:>15}{“折旧值”:>25}{“折旧”:>15}') #计算每年的结果并向用户显示 初始成本=成本 总折旧=0 范围内的年份(年): 折旧值=成本*费率 折旧成本=成本-折旧价值 总折旧+=折旧值 打印(f'{年+1:15.2f}{折旧成本:25.2f}{折旧价值:15.2f}') 成本=折旧成本 #向用户显示结果 打印(f'\n\n沉积速率为:{rate:.2f}') 打印(f'计划结束时的总折旧:${总折旧:.2f}')
#用于决定大小公寓的常数
大=0.10
小=0.08
#获取用户信息的输入
'''
只需循环直到输入有效值,而不是重新启动整个程序
将所有输入包含在1个循环中并不理想,因为错误会迫使用户重新开始,
您可以将每个输入拆分为自己的循环,以提升体验
'''
尽管如此:
尝试:
成本=浮动(输入(“输入房屋价值:\n”))
size=(输入(“您的公寓有多大?(大或小):\n”)。upper()
如果大小不在[‘大’、‘小’]:
打印(“请输入有效尺寸:大或小”)
持续
years=int(输入(“计划有多长?(年):\n”))
Exception ValueError:#调用值错误,不要让Exception打开
打印(“请输入有效值”)
其他:
#费率选择
如果大小=‘大’:比率=大
其他:费率=小
中断#如果未发生值验证错误,则中断循环
#表的标题
打印(f'\n{“年”:>10}{“当前值”:>15}{“折旧值”:>25}{“折旧”:>15}')
#计算每年的结果并向用户显示
初始成本=成本
总折旧=0
范围内的年份(年):
折旧值=成本*费率
折旧成本=成本-折旧价值
总折旧+=折旧值
打印(f'{年+1:15.2f}{折旧成本:25.2f}{折旧价值:15.2f}')
成本=折旧成本
#向用户显示结果
打印(f'\n\n沉积速率为:{rate:.2f}')
打印(f'计划结束时的总折旧:${总折旧:.2f}')

不相关但重要:
size==“Large”或“Large”始终为。不相关但重要:
size==“Large”或“Large”始终为。