首页 > 解决方案 > 修复输出的显示

问题描述

我的代码工作得很好,但是我在尝试使输出看起来像图片上的那样时遇到了麻烦。我需要有完全相同的空间(精确显示)。我不需要改变颜色,只需要改变空间和显示。请帮忙!图片

name = input("Enter employee's name: ")

hours = float(input("Enter number of hours worked in a week: "))

payRate = float(input("Enter hourly pay rate: "))

fedTaxWithholdingRate = float(input("Enter federal tax withholding rate (ex. 0.12): "))

stateTaxWithholdingRate = float(input("Enter state tax withholding rate (ex. 0.06): "))

grossPay = hours * payRate

fedTaxWithholding = grossPay * fedTaxWithholdingRate

stateTaxWithholding = grossPay * stateTaxWithholdingRate

totalDeduction = fedTaxWithholding + stateTaxWithholding

netPay = grossPay - totalDeduction

print("Employee Name: " + name) 

print("Hours Worked: " + str(hours))

print("Pay Rate: $" + str(payRate)) 

print("Gross Pay: $" + str(grossPay))

print("Deductions:\n")

print(" Federal Withholding (" + str(fedTaxWithholdingRate * 100) + \
 "%): $" + str(int(fedTaxWithholding * 100) / 100.0))

print(" State Withholding (" + str(stateTaxWithholdingRate * 100) + "%):" + \
 " $" + str(int(stateTaxWithholding * 100) / 100.0))

print(" Total Deduction:" + " $" + \
 str(int(totalDeduction * 100) / 100.0))

print("Net Pay:" + " $" + str(int(netPay * 100) / 100.0))

标签: python

解决方案


" " * number_of_spaces + "your string"在某些地方添加


推荐阅读