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