社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何让python只在你说“嗨”的时候回复

Nofal • 5 年前 • 1663 次点击  

我想先打个招呼,然后你得打个招呼,然后在那儿打个招呼。如果你不打,它会告诉你打个招呼。

hello = input('Hello')

def hiOrHey(hello):
    if hello == 'hi':
        if True:
            print("Hey there!")
    else:
        print("SAY HI")

但是,它不起作用,它只是说“你好!”,并留下一个空行。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54033
 
1663 次点击  
文章 [ 3 ]  |  最新文章 5 年前
Dharmveer Singh
Reply   •   1 楼
Dharmveer Singh    5 年前

你在叫你的函数hiOrHey吗。

如果不是,那就叫它。

def hiOrHey(hello): 
    if hello == 'hi':
        print("Hey there!") 
    else: 
        print("SAY HI")
hello = input('Hello')
hiOrHey(hello)
chrischris96
Reply   •   2 楼
chrischris96    5 年前
def hiOrHey(hello):
    print("hello")

    if hello == 'hi':
        print("Hey there!")
    else:
        print("SAY HI")

hiOrHey(hello)

文件名

PacketLoss
Reply   •   3 楼
PacketLoss    5 年前
  1. 你从来不叫你的函数
  2. 你不需要检查 if True 在检查值是否匹配之后,这是多余的。

以下内容将帮助您开始。

def hiOrHey(hello):
    if hello.lower() == 'hi': # Check if hello in lowercase matches hi
        print("Hey there!")
    else:
        print("SAY HI")

hello = input('Say Hi: ')

hiOrHey(hello) # Call your function, passing variable hello