python - 修复输出的显示
问题描述
我的代码工作得很好,但是我在尝试使输出看起来像图片上的那样时遇到了麻烦。我需要有完全相同的空间(精确显示)。我不需要改变颜色,只需要改变空间和显示。请帮忙!图片
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))
解决方案
" " * number_of_spaces + "your string"
在某些地方添加
推荐阅读
- c - 我在 C 中的 EqualsIgnoreCase 实现不起作用
- c++ - Eigen中的C ++静态数据成员初始化错误
- asp.net - 在后台代码 ASP.net 中使用条件时使用甜蜜警报确认
- reactjs - Typescript React 17 Tailwind CSS 2.0 安装
- java - java方法中二维数组行中条目的总和
- java - React Native 生产构建不起作用(Android)
- python - Python:如何将在执行 A 期间创建的变量从脚本 A 导入到脚本 B?
- java - 在 JFrame 中显示 java 程序中生成的 pdf 文档的内容,无需创建 pdf 文件
- validation - Oracle ADF 页面生命周期以及如何执行验证检查
- unit-testing - 如何告诉 Makemaker 并行运行测试?