'function named to_ransom_case that returns each character has been randomly transformed to either uppercase or lowercase in python
Create a function named to_ransom_case that accepts a single string argument (a message) and returns the message after each character has been randomly transformed to either uppercase or lowercase.
Solution 1:[1]
This should work:
import random
def to_ransom_case(s):
return_string = ""
for letter in s:
if random.randint(0, 1) == 0:
return_string += letter.capitalize()
else:
return_string += letter.lower()
return return_string
It goes through everey letter in the word and then randomize whether it will be capitalized or lower cased.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vate |
