-
Notifications
You must be signed in to change notification settings - Fork 0
Functions Module
from zcscommonlib import functionsTakes an input of an integer and returns a string of the month of that number.
num (int): The number of the month.
The month's name in string format.
# Imports
from zcscommonlib import functions
# Main program logic
month = functions.month(5)
print(month)
# Output: MayGets the input from a user, persisting until the input of the right type is received with an optional input message and error message.
type_in (str): The type of input to require of the user (int, float, str, bool).
input_msg (str): The message to display to the user when getting input.
error_msg (str): The error to log to console when an input of the wrong type is given.
The input provided from the user in the desired format.
# Imports
from zcscommonlib import functions
# Main program logic
userInput = functions.typed_input("int", "Please input an integer to multiply by 11: ", "This is not a valid integer.")
# User input: "Please input an integer to multiply by 11: 5"
print(str(userInput * 11))
# Output: 55Takes an input, in the form of a string, and checks if it is a palindrome.
input_str (str): A string you want to check.
is_word (bool): Is the value a single word?
Returns a boolean of if the word/string is a palindrome and a string of the word reversed (only if is_word is set to True) in the following format:
(bool, str)
# Imports
from zcscommonlib import functions
# Main program logic
inputWord = functions.typed_input("str", "Please provide a word to check if it is a palindrome: ", "This is not a valid input.")
# User input: "Please provide a word to check if it is a palindrome: Racecar"
isPalindrome, reversedStr = functions.palindrome(inputWord, True) == (True, 'racecaR')
print(inputWord + " in reverse is " + reversedStr + ".")
# Check if the word was a palindrome.
if isPalindrome:
print("Therefore, your input is a palindrome.")
else:
print("Therefore, your input is not a palindrome.")
# Output: Racecar in reverse is racecaR.
# Output: Therefore, your input is a palindrome.Takes an input, in the form of a string, and checks how many palindromes are in it. Also returns an array of those palindromes.
input_str (str): A string you want to check.
Returns an integer of how many palindromes are in the string and an array of all of the palindromes in the provided string in the following format:
(int, [str, str2...])
# Imports
from zcscommonlib import functions
# Main program logic
inputStr = functions.typed_input("str", "Please provide a sentence to check for palindromes: ", "This is not a valid input.")
# User input: "Please provide a sentence to check for palindromes: The racecar drives around madam as she talks to her mom."
palindrome_amount, palindromes = functions.palindromes(inputStr)
if palindrome_amount == 1:
print("There is one palindrome in the sentence you provided. It is \"" + palindromes[0] + "\".")
elif palindrome_amount > 0:
print("There are " + str(palindrome_amount) + " palindromes in the sentence you provided. They are \""
+ str(palindromes) + "\".")
else:
print("There are no palindromes in that sentence.")
# Output: There are 3 palindromes in the sentence you provided. They are "['racecar', 'madam', 'mom']"Takes an array and returns a random value from it.
array (list): An array to retrieve the value from.
A random value from the array
# Imports
from zcscommonlib import functions
# Main program logic
myArray = ['value1', 'value2', 'value3']
randomArrayValue = functions.random_value(myArray)
print(randomArrayValue)
# Output: value2Software by Zandercraft. Thank you for using the ZCS Common Library!