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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.