Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getstring_length():
- """ A function that checks whether the user has entered in a 3 character long string.
- A valid string is returned
- """
- answer = input("Please enter a string with 3 characters > ")
- while len(answer) !=3:
- answer = input("You have entered an incorrect string, please enter again > ")
- return answer
- #_____________________________________
- def getstring_in_list():
- """ A function that checks to see if the user has entered in a valid option
- from a list. A valid string is returned
- """
- validList = ["N","n","No","no"]
- answer = input("Please enter in 'no' to continue > ")
- while answer not in validList:
- answer = input("You have entered an invalid option, please enter in 'no'")
- return answer
- #_____________________________________
- def getstring_is_digit():
- """A function that checks if the user has entered a an integer. A valid string is returned
- """
- answer = input("Please enter an integer > ")
- while not answer.isdigit():
- answer = input("You have not entered an integer value, please try again > ")
- return int(answer)
- #_____________________________________
- def getstring_in_range():
- """ A function that checks if an entered number is between 1 and 100. A valid string is returned.
- """
- answer = input("Please enter a number between 1 and 100 ->")
- while int(answer) not in range(1,101): #setting the range
- print("You have entered in an incorrect number")
- answer = input("Please enter a number between 1 and 100 -> ")
- return answer
- #_____________________________________
- def getstring_is_alpha():
- """ A function that checks whether a string entered is just one word. A valid string is returned
- """
- answer = input("Please enter an single word -> ")
- while not answer.isalpha():
- print("You have entered an invalid quantity of words")
- answer = input("please enter a single word -> ")
- return answer
- #_____________________________________
- def getstring_exist():
- """ A function which checks whether you have entered something or not, valid string is returned
- """
- answer = input("Please enter your name -> ")
- while answer == "":
- print("I'm sorry, i didn't catch that.")
- asnwer = input("Please enter your name -> ")
- return answer
- #_____________________________________
- # Main Program
- print("Welcome to the unbreakable program")
- ans1 = getstring_length()
- print("You have managed to enter in the 3 character length string: {0}\n".format(ans1))
- ans2 = getstring_in_list()
- print("You have managed to type {0} to be able to continue with this program\n".format(ans2))
- ans3 = getstring_is_digit()
- print("You have entered in the valid number: {0}".format(ans3))
- ans4 = getstring_in_range()
- print("You have managed to enter the number {0} which is between 1 and 100\n".format(ans4))
- ans5 = getstring_is_alpha()
- print("You have managed to enter in the valid word: {0}".format(ans5))
- ans6 = getstring_exist()
- print("Existence accepted - You have enter {0} to prove existance".format(ans6))
- print("Well done, you have made it through the unbreakable program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement