Input I';我对定义语句有更多的问题

Input I';我对定义语句有更多的问题,input,while-loop,undefined,Input,While Loop,Undefined,我试图用一个输入循环来定义语句。如果输入在语句之外,我唯一的问题是它会重复输入两次,这有点奇怪。当输入仅在while循环内时,它会给出未定义的amt错误 def Loan_Amount(amt): while True: amt = int(input("Please put in the loan amount you would like to take out: ")) if amt < 500:

我试图用一个输入循环来定义语句。如果输入在语句之外,我唯一的问题是它会重复输入两次,这有点奇怪。当输入仅在while循环内时,它会给出未定义的amt错误

    def Loan_Amount(amt):
    while True:
        amt = int(input("Please put in the loan amount you would like to take out: "))
        if amt < 500:
           print("Sorry, we don't offer loans below 500 dollars")
           continue
        elif amt >= 500:
           break
    print(Loan_Amount(amt))
def贷款金额(amt):
尽管如此:
amt=int(输入(“请输入您想要取出的贷款金额:”)
如果金额<500:
打印(“对不起,我们不提供低于500美元的贷款”)
持续
elif金额>=500:
打破
打印(贷款金额)
另一方面看起来很奇怪

    amt = int(input('Please put in the loan amount you would like to take out: '))
    
    def Loan_Amount(amt):
    while True:
        amt = int(input("Please put in the loan amount you would like to take out: "))
        if amt < 500:
           print("Sorry, we don't offer loans below 500 dollars")
           continue
        elif amt >= 500:
           break
    print(Loan_Amount(amt))
amt=int(输入('请输入您想要取出的贷款金额:'))
def贷款金额(金额):
尽管如此:
amt=int(输入(“请输入您想要取出的贷款金额:”)
如果金额<500:
打印(“对不起,我们不提供低于500美元的贷款”)
持续
elif金额>=500:
打破
打印(贷款金额)

好的,如果其他人遇到这个问题,我就不谈了,但是在看了文档之后,我发现了这个问题

   def Loan_Amount(prompt)
        While True:
             global amt
             amt = int(input(prompt))
             if amt < 500:
                  print("Sorry, we don't offer loans below 500 dollars")
                  continue

             else:
                  break
    Loan_Amount('Please put in the loan amount you would like to take out: ')
    print(amt)
def贷款金额(提示)
尽管如此:
全球金额
金额=整数(输入(提示))
如果金额<500:
打印(“对不起,我们不提供低于500美元的贷款”)
持续
其他:
打破
贷款金额('请输入您想取出的贷款金额:')
打印(金额)
我不能百分之百确定我是否会正确解释这一点,所以请仔细理解我的解释。基本上,它不是像def Loan_Amount(amt)那样将amt放在括号内,使其既是一个参数又是一个全局变量,而是一个提示符,而不是在循环内键入输入,它是在调用语句时键入的。全局amt部分在那里,我很确定,所以当amt被赋予一个数字时,它将使amt成为一个全局变量,而不是在循环内保持它的局部性,这样你就可以在循环外打印它,它仍然是一个定义的变量。希望这能帮助像我这样迷失的人