Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. def getProperStringValue(message, requiredLength):
  2. value = ""
  3. while len(value)<requiredLength:
  4. value = input(message)
  5. if len(value)<requiredLength:
  6. print("You're string is too short. You need to give at least", requiredLength, "characters!")
  7. return value
  8.  
  9. def getProperIntValue(message, minimum):
  10. value = None
  11. while not value:
  12. try:
  13. value = int(input(message))
  14. if value<minimum:
  15. print("You have to be above", minimum ,"age")
  16. value = None
  17. except:
  18. print("Age has to be an integer!")
  19. value = None
  20. return value
  21.  
  22. def getProperHeight(message, minimum, maximum):
  23. value = None
  24. while not value:
  25. try:
  26. value = int(input(message))
  27. if value<minimum:
  28. print("You have to be above", minimum ,"cm height")
  29. value = None
  30. if value>maximum:
  31. print("You have to be below", maximum ,"cm height")
  32. value = None
  33. except:
  34. print("Height has to be an integer!")
  35. value = None
  36. return value
  37.  
  38. while True:
  39. username = getProperStringValue("Type in your username: ", 1)
  40. password = getProperStringValue("Type in your password: ", 5)
  41. age = getProperIntValue("Type in your age: ", 16)
  42. height = getProperHeight("Type in your height: ", 100, 250)
  43.  
  44. with open('output.txt', 'a') as file:
  45. file.write("User: " + username + "\nPassword: " + password + "\nAge: " + str(age) + "\nHeight: " + str(height) + " cm\n")
  46. print("Username has been created correctly!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement