Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake.

Can you help her?

Difficulty: EASY

Starter code:
def greet(name):
	

Solutions:
def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	return 'Hello, {name}!'.format(name=name)


def greet(name):
	return 'Hello, {name}!'.format(name=name.replace('Johnny', 'my love'))


greet = lambda n: 'Hello, {}!'.format(n.replace('Johnny', 'my love'))


greet = lambda name: 'Hello, ' + ('my love' if name == 'Johnny' else name) + '!'


def greet(name):
	return 'Hello, my love!' if name == 'Johnny' else f'Hello, {name}!'


greet = lambda n: 'Hello, {}!'.format('my love' if n == 'Johnny' else n)


def greet(name):
	return 'Hello, my love!' if name == 'Johnny' else 'Hello, %s!' % name


def greet(name):
	return 'Hello, my love!' if name == 'Johnny' else 'Hello, {0}!'.format(name)


greet = lambda n: {'Johnny': 'Hello, my love!'}.get(n, 'Hello, {}!'.format(n))


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	elif name == 'James':
		return 'Hello, James!'
	elif name == 'Jane':
		return 'Hello, Jane!'
	elif name == 'Jim':
		return 'Hello, Jim!'


def greet(name):
	a = lambda m: 'Hello, my love!' if m == 'Johnny' else 'Hello, {}!'.format(m)
	return a(name)


greet = lambda n: f"Hello, {[n, 'my love'][n == 'Johnny']}!"


def greet(n):
	if n == 'Johnny':
		return 'Hello, my love!'
	else:
		return f'Hello, {n}!'


def greet(name):
	if name == 'Johnny':
		x = 'Hello, my love!'
	else:
		x = 'Hello, {name}!'.format(name=name)
	return x


def greet(name):
	result = 'Hello, {}!'.format(name)
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return result


def greet(name):
	if name != 'Johnny':
		return f'Hello, {name}!'
	elif name == 'Johnny':
		return 'Hello, my love!'


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return 'Hello, ' + name + '!'
greet('James')


def greet(name):
	greeting = ''
	if name == 'Johnny':
		greeting = 'Hello, my love!'
	else:
		greeting = 'Hello, ' + name + '!'
	return greeting
print(greet('Maria'))
print(greet('Johnny'))


def greet(name):
	if not name == 'Johnny':
		return 'Hello, ' + name + '!'
	if name == 'Johnny':
		return 'Hello, my love!'


def greet(name):
	if name.title() == 'Johnny':
		return 'Hello, my love!'
	else:
		return f'Hello, {name}!'.format(name)


def greet(name):
	if name != 'Johnny':
		return 'Hello, {guy}!'.format(guy=name)
	else:
		return 'Hello, my love!'


def greet(name):
	for i in name:
		if i in name == 'Johnny':
			return 'Hello, my love!'
		else:
			return 'Hello, ' + name + '!'


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	return 'Hello, ' + name + '!'
print(greet('Johnny'))


def greet(name):
	if name.lower() == 'johnny':
		return 'Hello, my love!'
	else:
		return f'Hello, {name}!'


def greet(name):
	lovers = {'Johnny'}
	return 'Hello, my love!' if name in lovers else f'Hello, {name}!'


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return f'Hello, {name}!'.format(name=name)
g = greet('Johnny')
print(g)


def greet(name):
	small_name = name.lower()
	n_a_m_e = list(small_name)
	x = 0
	if name == 'Johnny':
		return 'Hello, my love!'
	while x != len(n_a_m_e):
		if x == 0:
			n_a_m_e[x] = n_a_m_e[x].upper()
			x = x + 1
			print(x)
		elif x <= len(n_a_m_e):
			n_a_m_e[x] = n_a_m_e[x]
			x = x + 1
			print(x)
	n_a_m_e += '!'
	end = ['H', 'e', 'l', 'l', 'o', ',', ' '] + n_a_m_e
	end = ''.join(end)
	return end


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return 'Hello, {fname}!'.format(fname=name)


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return 'Hello, {name}!'.format(name=name)
greet('spoo')


def greet(name):
	return str('Hello, ' + name + '!') if name != 'Johnny' else str('Hello, my love!')


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		resp = 'Hello, ' + name + '!'
		return resp


def greet(name):
	return 'Hello, my love!' if name.lower() == 'johnny' else 'Hello, {}!'.format(name)


greet = lambda s: f"Hello, {('my love' if s == 'Johnny' else s)}!"


def greet(name):
	darling = {'Johnny': 'my love'}
	return f'Hello, {darling.get(name, name)}!'


def greet(name):
	if name == 'Johnny':
		return 'Hello, my love!'
	return 'Hello, {name}!'.format(name=name)
print(greet('Johny'))


def greet(name):
	greeting = 'Hello, {name}!'.format(name=name)
	if name == 'Johnny':
		return 'Hello, my love!'
	else:
		return greeting


greet = lambda n: 'Hello, my love!' if n == 'Johnny' else f'Hello, {n}!'


def greet(name):
	if name == 'Johnny':
		msg = 'Hello, my love!'
	else:
		msg = 'Hello, {name}!'.format(name=name)
	return msg