首页 > 其他分享 >Grasshopper - Personalized Message

Grasshopper - Personalized Message

时间:2023-03-16 12:22:51浏览次数:42  
标签:return name Grasshopper value Hello owner Personalized else Message

Instructions
Create a function that gives a personalized greeting. This function takes two parameters: name and owner.
Use conditionals to return the proper message:

case return
name equals owner 'Hello boss'
otherwise 'Hello guest'

Solution

def greet(name, owner):
    return "Hello boss" if name == owner else "Hello guest"

conditional expression:
value_if_true if condition else value_if_false
For example:

x = 10
y = "even" if x % 2 == 0 else "odd"
print(y) # prints "even"

标签:return,name,Grasshopper,value,Hello,owner,Personalized,else,Message
From: https://www.cnblogs.com/artwalker/p/17222092.html

相关文章