Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
THIS SCRIPT HAS NO USEFUL PRUPOSE. It is a script that was written up for a scenario at a SkillsUSA programming competition. It was supposed to connect any of 10 specified keywords to a randomized phone number. If the randomized keyword is one of the 10 knowns keywords, the call is excepted, but if the keyword did not match any of the known keyw…
import random
import string
accepted_keywords = [
"(nothing)",
"abc",
"deft",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz",
]
# Creates a random phone number
def random_phone_number():
phone_number = [random.randrange(10) for i in range(10)]
return "({}{}{}){}{}{}-{}{}{}{}".format(*phone_number)
# Creates randomized keyword that attaches to a phone number, then will be accepted
# if keyword matches one that is in the accepted keywords or is denied
def random_keyword():
keyword = "".join(
random.choice(string.ascii_lowercase) for i in range(random.choice([3, 4]))
)
chance = random.randrange(1, 7)
if chance == 2 or chance == 4:
keyword = random.choice(accepted_keywords)
number_and_keyword = (
"keyword: "
+ keyword
+ "\ncalls: 1\n"
+ str(random_phone_number())
+ "\nkeyword: exit\n"
)
print(
"input:\n"
+ number_and_keyword
+ "output:\n"
+ "\nkeyword: "
+ keyword
+ "\n*Accepted*\n"
if keyword in accepted_keywords
else "\ninput:\n"
+ number_and_keyword
+ "\noutput:"
+ "\nkeyword: "
+ keyword
+ "\nDenied\n"
)
random_keyword()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment