简体   繁体   English

当我运行我的程序时,我的输入没有显示出来。 为什么?

[英]My inputs do not show up when I run my program. Why?

How can I fix the inputs?我该如何修复输入? Because they do not show up when I run my program.因为当我运行我的程序时它们没有出现。

## Define the main module
def main():

    ## Initialize local Variables / Set Constant
    homeValue = 0
    propertyTaxRate = 0
    bedrooms = 0
    BEDROOMSURCHARGERATE = 0.0025

    ## Set initialized varialbes to user inputs
    homeValue = float(input("How much is your home worth?"))
    propertyTaxRate = float(input("What is your Property Tax Rate entered as a decimal?"))
    bedrooms = int(input("How many bedrooms will your house have?"))

    ## Set Variables equal to results of module outputs
    propertyTax = getPropertyTax(homeValue, propertyTaxRate)
    bedroomSurcharge = getBedroomSurcharge(BEDROOMSURCHARGERATE, bedrooms, homeValue)
    totalPropertyTax = getTotalPropertyTax(propertyTax, bedroomSurcharge)

    ## Report All information with a propertyTaxReport
    propertyTaxReport(homeValue, propertyTaxRate, bedrooms, propertyTax, bedroomSurcharge, totalPropertyTax)

## Define getPropertyTax Module
def getPropertyTax(homeValue, propertyTaxRate):

    ## Calculate property tax
    propertyTax = homeValue*propertyTaxRate

    return propertyTax

## Define getBedroomSurcharge
def getBedroomSurcharge(BEDROOMSURCHARGERATE, bedrooms, homeValue):

    ## Calculate Bedroom Surcharge
    bedroomSurcharge = BEDROOMSURCHARGERATE*bedrooms*homeValue

    return bedroomSurcharge

## Define getTotalPropertyTax
def getTotalPropertyTax(propertyTax, bedroomSurcharge):

    ## Calculate totalProperty Tax
    totalPropertyTax = propertyTax + bedroomSurcharge

    return totalPropertyTax

## Define propertyTaxReport
def propertyTaxReport(homeValue, propertyTaxRate, bedrooms, propertyTax, bedroomSurcharge, totalPropertyTax):

    ## Output Variables
    print("Your home costs ", homeValue, " dollars.")
    print("Your property tax rate is ", propertyTaxRate)
    print("Your house has ", bedrooms, "bedrooms")
    print("Your property tax is equal to ", propertyTax, " dollars.")
    print("Your bedroom surcharge is equal to ", bedroomSurchage, " dollars")
    print("Your total property tax comes out to ", totalPropertyTax, " dollars")
    return

I think you are drying a bit with your code.我认为您的代码有点干。 A few suggestions:几点建议:

  1. You do not need to initialise a variable if this is an input from the user.如果这是来自用户的输入,则不需要初始化变量。
  2. If you can simplify a calculation, just do it.如果你能简化计算,那就去做吧。 Do not create many functions if they are not necessary.如果不需要,不要创建很多函数。
  3. You do not to print as output variables that the user gives as input.您不打印用户作为输入提供的 output 变量。 I guess the user already knows that.我想用户已经知道了。 But if it is a serious report, maybe I can give you that.但如果这是一份严肃的报告,也许我可以给你。

Try this and let me know:试试这个,让我知道:

def main_function():
    BEDROOMSURCHARGERATE = 0.0025

    ## Set initialized variables to user inputs
    homeValue = float(input("How much is your home worth?"))
    propertyTaxRate = float(input("What is your Property Tax Rate entered as a decimal?"))
    bedrooms = int(input("How many bedrooms will your house have?"))

    ## Set Variables equal to results of module outputs
    propertyTax = homeValue*propertyTaxRate
    bedroomSurcharge = BEDROOMSURCHARGERATE*bedrooms*homeValue
    totalPropertyTax = propertyTax + bedroomSurcharge

    ## Report all information with a propertyTaxReport
    return (totalPropertyTax, f"bedroom Surcharge was {bedroomSurcharge}")

To call the function just do:要拨打 function,只需执行以下操作:

main_function()

You can return this tuple or print the whole thing you have at the end, up to you.您可以返回此元组或打印最后的全部内容,由您决定。 I just point out that you can return just a value or a sentence.我只是指出您可以只返回一个值或一个句子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行程序时出现无限循环。 我如何解决它? - I am getting an infinite loop when I run my program. How do I fix it? 为什么我在运行程序时输入的前两个输入会在文本文件中重复? - Why do the first two inputs I enter when I run my program repeat in the text file? 在我的程序中,我想在hero的生命值为0而不是整个程序时退出该函数。 我可以做什么? - In my program I want To exit the function when the health of hero is 0 not the whole program. What I can do? 运行程序时保存并加载QListItems。 - Save & Load QListItems when I'm running my program. 我从我的电脑中删除了一些文件,现在我无法运行脚本/程序。 我该怎么办? - I deleted some files from my computer and now I can't run a script/program. What do I do? 为什么在启动时启动程序时,通知区域图标没有显示? - Why does my notification area icon not show up when I launch my program on startup? 为什么python,当我运行我的程序时出现错误&#39;预期缩进块? - Why does python, when I run my program comes up with the error 'expected an indented block? 当我运行我的代码时,为什么椭圆/圆没有出现 - when i run my code, why does the ellipse/circle not show up 为什么附近会出现语法错误<mygrid>当我运行我的 kv 文件时?</mygrid> - Why does a syntax error show up near <MyGrid> when I run my kv file? 导入logging.handlers破坏了我的程序。 为什么? - import logging.handlers breaks my program. Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM