Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally.

Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work out if you make it home safely. 15 bumps or under, return "Woohoo!", over 15 bumps return "Car Dead".

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def bumps(road):
	

Solutions:
def bumps(road):
	return 'Woohoo!' if road.count('n') <= 15 else 'Car Dead'


def bumps(road):
	return 'Woohoo!' if road.count('n') < 16 else 'Car Dead'


from collections import Counter

def bumps(road):
	return 'Car Dead' if Counter(road)['n'] > 15 else 'Woohoo!'


import re

def bumps(road):
	return 'Woohoo!' if len(re.findall('n', road)) < 16 else 'Car Dead'


def bumps(road):
	MAX_BUMPS = 15
	SUCCESS_MESSAGE = 'Woohoo!'
	ERROR_MESSAGE = 'Car Dead'
	return SUCCESS_MESSAGE if road.count('n') <= MAX_BUMPS else ERROR_MESSAGE


bumps = lambda road: 'CWaoro hDoeoa!d'[road.count('n') < 16::2]


def bumps(road):
	return ('Woohoo!', 'Car Dead')[road.count('n') > 15]


def bumps(road):
	track = 0
	for el in road:
		if el == 'n':
			track += 1
	if track > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	a = 0
	for i in road:
		if i == 'n':
			a += 1
	if a > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	bumps = 0
	for c in road:
		if c == 'n':
			bumps += 1
	if bumps <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	L = list(road)
	C = L.count('n')
	if C > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	commute = road
	bumps = commute.count('n')
	condition_1 = bumps < 16
	condition_2 = bumps >= 16
	if condition_1:
		return 'Woohoo!'
	if condition_2:
		return 'Car Dead'


def bumps(road):
	return 'Car Dead' if len([r for r in road if r is 'n']) > 15 else 'Woohoo!'

def best_practice_bumps(road):
	return 'Woohoo!' if road.count('n') <= 15 else 'Car Dead'


def bumps(road):
	x = road.count('n')
	results = ['Woohoo!', 'Car Dead']
	if x > 15:
		return results[1]
	else:
		return results[0]


def bumps(road):
	c = road.count('n')
	if c > 15:
		return 'Car Dead'
	return 'Woohoo!'


def bumps(road):
	bumps = road.count('n')
	if bumps > 15:
		return 'Car Dead'
	elif bumps <= 15:
		return 'Woohoo!'


def bumps(road):
	k = list(road)
	count = 0
	for word in k:
		if word == 'n':
			count += 1
	if count < 16:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(s):
	return 'Woohoo!' if s.count('n') < 16 else 'Car Dead'


def bumps(road):
	count = 0
	for i in road:
		if i == 'n':
			count += 1
	if count <= 15:
		return 'Woohoo!'
	return 'Car Dead'


def bumps(road):
	bumps = [x for x in road if x == 'n']
	if len(bumps) > 15:
		return 'Car Dead'
	return 'Woohoo!'


bumps = lambda s: 'Woohoo!' if s.count('n') < 16 else 'Car Dead'


def bumps(road):
	count = 0
	for char in road:
		if char == 'n':
			count += 1
	if count > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	list(road)
	bump_counter = 0
	for bump in road:
		if bump == 'n':
			bump_counter += 1
	if bump_counter <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	counter = -1
	bumps = 0
	for x in road:
		counter += 1
		if road[counter] == 'n':
			bumps += 1
			print(bumps)
	if bumps <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	bumps = 0
	for i in range(len(road)):
		if road[i] == 'n':
			bumps += 1
		if bumps > 15:
			return 'Car Dead'
	return 'Woohoo!'


def bumps(s):
	return 'Woohoo!' if s.count('n') <= 15 else 'Car Dead'


def bumps(road):
	count = 0
	for x in road:
		if x is 'n':
			count = count + 1
	if count > 15:
		x = 'Car Dead'
	else:
		x = 'Woohoo!'
	return x


def bumps(road):
	x = 0
	for spot in road:
		if spot == 'n':
			x += 1
		else:
			continue
	if x > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	(cnt1, cnt2) = (0, 0)
	for c in road:
		if c == '_':
			cnt1 += 1
		elif c == 'n':
			cnt2 += 1
		if cnt2 > 15:
			return 'Car Dead'
	return 'Woohoo!'


f1 = lambda x: 1 if x == 'n' else 0
f2 = lambda x: 'Woohoo!' if x <= 15 else 'Car Dead'

def bumps(road):
	return f2(sum((f1(x) for x in road)))


def bumps(road):
	ncount = 0
	a = [char for char in road]
	for i in range(len(a)):
		if a[i] == 'n':
			ncount += 1
	if ncount > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	flat = []
	bump = []
	for letter in road:
		if letter is '_':
			flat.append(letter)
		else:
			bump.append(letter)
	if len(bump) <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	bumps = 0
	for letter in road:
		if letter == 'n' or letter == 'N':
			bumps += 1
		elif letter == '_':
			continue
		else:
			continue
	if bumps > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	bumps = 0
	for letter in road:
		if letter == 'n':
			bumps += 1
			continue
		else:
			continue
	if bumps > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	nr_bumps = 0
	for c in road:
		if c == 'n':
			nr_bumps += 1
	return 'Woohoo!' if nr_bumps < 16 else 'Car Dead'


def bumps(road):
	a = 0
	for char in road:
		if str(char) == 'n':
			a += 1
	if a <= 15:
		return 'Woohoo!'
	if a > 15:
		return 'Car Dead'


def bumps(road):
	counter = 0
	for i in road:
		if i == 'n':
			counter += 1
			continue
	return 'Woohoo!' if counter <= 15 else 'Car Dead'


def bumps(road):
	return 'Car Dead' if ''.join(sorted(road, reverse=True)[0:16]) == 'nnnnnnnnnnnnnnnn' else 'Woohoo!'


def bumps(road):
	x = road.count('n')
	if x <= 15:
		return 'Woohoo!'
	return 'Car Dead'


def bumps(road):
	roadList = list(road)
	speedBumps = 'n'
	bumpCount = 0
	for i in roadList:
		if i == 'n':
			bumpCount += 1
	if bumpCount > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	return 'Woohoo!' if len(list(filter(lambda x: x == 'n', road))) <= 15 else 'Car Dead'


def bumps(road):
	list = [road]
	a = 0
	for x in road:
		if x == 'n':
			a = a + 1
	if a > 15:
		return 'Car Dead'
	return 'Woohoo!'


def bumps(road):
	countN = 0
	countUnderscore = 0
	listletters = [char for char in road]
	for i in listletters:
		if i == 'n':
			countN += 1
		else:
			countUnderscore += 1
	if countN > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	bump = 0
	for s in road:
		if s == 'n':
			bump += 1
	return 'Woohoo!' if bump <= 15 else 'Car Dead'


def bumps(road):
	return 'Car Dead' if len(list(filter(str.isalpha, road))) > 15 else 'Woohoo!'


def bumps(road):
	bumps = 0
	for i in road:
		if i == '_':
			pass
		elif i == 'n':
			bumps += 1
	if bumps > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	dead = 0
	for x in road:
		if x == 'n':
			dead += 1
	if dead > 15:
		return 'Car Dead'
	else:
		return 'Woohoo!'


def bumps(road):
	count = 0
	for each in road:
		if each == 'n':
			count += 1
	if count > 15:
		return 'Car Dead'
	elif count <= 15:
		return 'Woohoo!'


def bumps(road):
	road_list = list(road)
	bump_number = 0
	for segment in road_list:
		if segment == 'n':
			bump_number += 1
	if bump_number <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	n = [x for x in road if x == 'n'].count('n')
	return 'Woohoo!' if n <= 15 else 'Car Dead'


def bumps(road):
	sum = 0
	for i in road:
		if i is 'n':
			sum += 1
		if sum > 15:
			return 'Car Dead'
	return 'Woohoo!'


def bumps(road):
	return 'Woohoo!' if len(road.split('n')) <= 16 else 'Car Dead'


bumps = lambda road: 'Woohoo!' if road.count('n') < 16 else 'Car Dead'


def bumps(road):
	b = 0
	for x in road:
		if x == 'n':
			b = b + 1
	if b < 15:
		return 'Woohoo!'
	elif b == 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'


def bumps(road):
	num_bumps = road.count('n')
	if num_bumps > 15:
		return 'Car Dead'
	return 'Woohoo!'


def bumps(road):
	lista = list(road)
	bumps = 0
	for i in lista:
		if i == 'n':
			bumps += 1
	if bumps <= 15:
		return 'Woohoo!'
	else:
		return 'Car Dead'