I can't for the life of me solve this problem :icon_confused:

Write a function called rand_goodbye(name) that returns (not prints!) a string that says goodbye, where the goodbye phrase is chosen at random from these three possibilities:

* Goodbye name
* See ya' later name
* name: stay cool!

I'm trying to use the random.randint function but it's not working...
Any help would be greatly appreciated as it's driving me insane.

2
Contributors
1
2
Views
7 Years
Discussion Span
Last Post by lukerobi

I can't for the life of me solve this problem :icon_confused:

Write a function called rand_goodbye(name) that returns (not prints!) a string that says goodbye, where the goodbye phrase is chosen at random from these three possibilities:

* Goodbye name
* See ya' later name
* name: stay cool!

I'm trying to use the random.randint function but it's not working...
Any help would be greatly appreciated as it's driving me insane.

``````from random import randint

def rand_goodbye(name):
byes = {1: 'goodbye REPLACENAME', 2: 'See ya later REPLACENAME', 3: 'REPLACENAME: stay cool!'}
goodbye = str(byes[randint(1,3)]).replace('REPLACENAME', name)
return goodbye``````

Thats probally not the best way to do it... but it will work.

**EDIT**

This is better:

``````from random import randint

def rand_goodbye(name):
byes = {1: 'goodbye %s' %name, 2: 'See ya later %s' %name, 3: '%s: stay cool!' %name}
goodbye = byes[randint(1,3)]
return goodbye``````

Sorry.. im a bit tired and brain dead lol

Edited by lukerobi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.