简体   繁体   English

我想在 python 中编写一个名为 cont() 的函数,它发送一条消息“继续”并且不应该带任何参数

[英]i want to write a function in python named cont() which sends a message "continue" and which should take no argument

i want to write a function in python named cont() which sends a message "continue" and which should take no argument.the function should print the message yes,y or Y.then return true otherwise false.我想在 python 中编写一个名为 cont() 的函数,它发送一条消息“继续”并且不应该带任何参数。该函数应该打印消息 yes、y 或 Y。然后返回 true 否则返回 false。 i have done it but there is an error.我已经做到了,但有一个错误。

def cont():
    x = input("enter any word of your choice")
    for letter in 'x':
        if letter == '[0]':
            a = input ("continue")
            if a == 'yes' == 'y' == 'Y' :
                continue
            print 'current letter will be:',letter
        else:
            print x

if __name__=="__main__":
    cont()

Sadly the code that you supplied and the description that you wrote, do not agree with each other.遗憾的是,您提供的代码和您编写的描述彼此不一致。 There is no attempt to return any value, indeed, there is nothing to suggest what the decision of True or False would be based upon.没有尝试return任何值,实际上,没有任何内容表明TrueFalse的决定将基于什么。
Assuming that you are using python 2.7, this should get you started:假设您使用的是 python 2.7,这应该让您开始:

def cont():
    x = raw_input("Enter any word of your choice: ")
    for letter in x:
#    if letter == '[0]':
        a = raw_input ("Continue? ")
        if a == 'yes' or a == 'y' or a == 'Y' :
#            continue
            print 'Current letter will be:',letter
        else:
            print x
            break
if __name__ == '__main__':
    cont()

I have no idea what you were attempting to do with the if letter == '[0]': or the continue lines, so I have commented them out.我不知道你试图用if letter == '[0]':continue行做什么,所以我已经将它们注释掉了。 If you wish to return a value, simply return True or return False at the point of your choosing in the code.如果您希望返回一个值,只需在您在代码中选择的位置return Truereturn False The other option is to set a variable to True or False and then, as the last statement of cont() use the return keyword with the variable.另一种选择是将变量设置为TrueFalse ,然后,作为cont()的最后一条语句,将return关键字与变量一起使用。

Note: if you are using python3 the raw_input becomes input and the print commands become print()注意:如果你使用 python3, raw_input变成inputprint命令变成print()

暂无
暂无

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

相关问题 DISCORD.PY PYTHON-我要创建一个函数,当用户加入服务器时在服务器中发送全局消息 - DISCORD.PY PYTHON - I want to make a function which sends a global message in the server when a user joins in the server Windows上的python 3.5。 该程序应该发送一个文本文件,它会读取并发送一个Empty消息 - python 3.5 on windows. the program should send a text file which it reads and it sends an emty message 对于 Python 中的错误/非法参数组合,我应该引发哪个异常? - Which exception should I raise on bad/illegal argument combinations in Python? 我应该使用哪个库来编写Linux / Python的XLS? - Which library should I use to write an XLS from Linux / Python? 我将如何编写一个机器人,在目标用户更改其自定义状态时向其所有者发送直接消息? - How would I write a bot which sends it's owner a direct message whenever a target user changes their custom status? 为什么 python 程序在我将文件移动到另一个目录后继续写入它原来所在的目录? - Why does a python program continue to write to the directory in which it was originally located, after I move the file to another directory? python列表问题,我应该使用哪个函数? - python list problem, which function should I use? Python 我应该使用哪个 itertools 模块 function? - Python which itertools module function should I use? 我想取数据集中一个值的最大值和最小值,该值与 python 中的其他几个值 - I want to take the max and min value of a value in a data set which with several other values in python python采用单个参数输入,可以是两种不同的类型 - python take single argument input which can be two different types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM