Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getProperStringValue(message, requiredLength):
- value = ""
- while len(value)<requiredLength:
- value = input(message)
- if len(value)<requiredLength:
- print("You're string is too short. You need to give at least", requiredLength, "characters!")
- return value
- def getProperIntValue(message, minimum):
- value = None
- while not value:
- try:
- value = int(input(message))
- if value<minimum:
- print("You have to be above", minimum ,"age")
- value = None
- except:
- print("Age has to be an integer!")
- value = None
- return value
- def getProperHeight(message, minimum, maximum):
- value = None
- while not value:
- try:
- value = int(input(message))
- if value<minimum:
- print("You have to be above", minimum ,"cm height")
- value = None
- elif value>minimum:
- print("You have to be below", maximum ,"cm height")
- value = None
- except:
- print("Height has to be an integer!")
- value = None
- return value
- while True:
- username = getProperStringValue("Type in your username: ", 1)
- password = getProperStringValue("Type in your password: ", 5)
- age = getProperIntValue("Type in your age: ", 16)
- height = getProperHeight("Type in your height: ", 100, 250)
- with open('output.txt', 'a') as file:
- file.write("User: " + username + "\nPassword: " + password + "\nAge: " + str(age) + "\nHeight: " + str(height) + " cm\n")
- print("Username has been created correctly!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement