Advertisement
joeyturner123

The Unbreakable Program 1.0

Mar 20th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. def getstring_length():
  2.         """ A function that checks whether the user has entered in a 3 character long string.
  3.              A valid string is returned
  4.        """
  5.         answer = input("Please enter a string with 3 characters > ")
  6.         while len(answer) !=3:
  7.           answer = input("You have entered an incorrect string, please enter again > ")
  8.    
  9.         return answer
  10. #_____________________________________
  11.    
  12. def getstring_in_list():
  13.         """ A function that checks to see if the user has entered in a valid option
  14.            from a list. A valid string is returned
  15.        """
  16.         validList = ["N","n","No","no"]
  17.         answer = input("Please enter in 'no' to continue > ")
  18.         while answer not in validList:
  19.           answer = input("You have entered an invalid option, please enter in 'no'")
  20.        
  21.         return answer
  22. #_____________________________________
  23.  
  24. def getstring_is_digit():
  25.         """A function that checks if the user has entered a an integer. A valid string is returned
  26.        """
  27.         answer = input("Please enter an integer > ")
  28.         while not answer.isdigit():
  29.           answer = input("You have not entered an integer value, please try again > ")
  30.  
  31.         return int(answer)
  32.                                  
  33. #_____________________________________
  34.  
  35. def getstring_in_range():
  36.         """ A function that checks if an entered number is between 1 and 100. A valid string is returned.
  37.        """
  38.         answer = input("Please enter a number between 1 and 100 ->")
  39.  
  40.         while int(answer) not in range(1,101):      #setting the range
  41.             print("You have entered in an incorrect number")
  42.             answer = input("Please enter a number between 1 and 100 -> ")
  43.    
  44.         return answer
  45.    
  46. #_____________________________________
  47.  
  48. def getstring_is_alpha():
  49.     """ A function that checks whether a string entered is just one word. A valid string is returned
  50.    """
  51.  
  52.     answer = input("Please enter an single word -> ")
  53.  
  54.     while not answer.isalpha():
  55.         print("You have entered an invalid quantity of words")
  56.         answer = input("please enter a single word -> ")
  57.  
  58.     return answer
  59. #_____________________________________
  60.  
  61. def getstring_exist():
  62.     """ A function which checks whether you have entered something or not, valid string is returned
  63.    """
  64.     answer = input("Please enter your name -> ")
  65.  
  66.     while answer == "":
  67.         print("I'm sorry, i didn't catch that.")
  68.         asnwer = input("Please enter your name -> ")
  69.  
  70.     return answer
  71.  
  72. #_____________________________________
  73.  
  74. # Main Program
  75. print("Welcome to the unbreakable program")
  76. ans1 = getstring_length()
  77. print("You have managed to enter in the 3 character length string: {0}\n".format(ans1))
  78.  
  79. ans2 = getstring_in_list()
  80. print("You have managed to type {0} to be able to continue with this program\n".format(ans2))
  81.  
  82. ans3 = getstring_is_digit()
  83. print("You have entered in the valid number: {0}".format(ans3))
  84.  
  85. ans4 = getstring_in_range()
  86. print("You have managed to enter the number {0} which is between 1 and 100\n".format(ans4))
  87.  
  88. ans5 = getstring_is_alpha()
  89. print("You have managed to enter in the valid word: {0}".format(ans5))
  90.  
  91. ans6 = getstring_exist()
  92. print("Existence accepted - You have enter {0} to prove existance".format(ans6))
  93.  
  94.  
  95.  
  96. print("Well done, you have made it through the unbreakable program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement