【问题标题】:return to a part of my script? [closed]返回到我的脚本的一部分? [关闭]
【发布时间】:2023-03-23 21:25:01
【问题描述】:

我可以做一个这样的功能吗:

def again ():
   again = input ( "want to input the word again ?  yes =1 no =2 ")
   if again == 1:
        func_input_word()
   else:
        return keuzemaken

【问题讨论】:

  • 首先,你想做什么?二 mij input_word 在哪里?
  • 用户选择一个选项(选项1),他必须输入一个超过6个字母的单词,如果该单词不超过6个,它必须返回并再次询问input_word .这就是我想要的。

标签: python function input return


【解决方案1】:

我猜这段代码会做你想做的事:

def func_input_word():
    input_word = ""
    while len(input_word) < 6:
        input_word = input("Input a 6 letter word: ")
        if len(input_word) < 6:
            print("Too small, try again!")
        else:
            return input_word
def option(my_choose):  #function named: make choose ( choice )
    if my_choose == 1:
        input_word = func_input_word()
    else:
        ....

【讨论】:

  • 如果您使用的是 python 2.x,请改用 raw_input。
  • 不,它是一个 python 3 脚本,但是如果我需要更多帮助,我可以给你发邮件或其他什么吗?
  • 如果我做你做的一些事情,我会得到一个语法错误,因为我在我的其他功能中没有 if ??
  • 好的.. 我要编辑它。但我测试了它,它没有出错。
  • 不,这部分没问题,但如果我调用它,它会给我一个错误,我将在我的问题中编辑它我调用的部分
【解决方案2】:

这个怎么样:

def option(my_choose):  #function named: make choose ( choice )
   if my_choose == 1:
       while len(input_word) < 6:
          input_word = input( "type het gekozen 6 letterig woord in : ") #input for word
          if len(input_word) < 6:
             print ("to short, try again ")
          else:
             break
    else:
    ....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-31
    • 2019-09-01
    • 2013-08-27
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多