I'm a beginner of Python's path, need help. I need all the data to meet all the conditions I set. And if one condition is not met, then he will not print the "else".
That is, if the software prints an error it will not print the "else". Only if the software meets all the conditions at the end will print the else without "error "messages.
from datetime import datetime
data_user = input("Please enter contact details (first name, last name, birth (year), cellular phone number (10 digits) :").split(" ")
if len(data_user) != 4:
print("Error: the data was entered in the wrong order or there is a missing input or the input is incorrect.")
first_name = data_user[0]
last_name = data_user[1]
phone_number = data_user[2]
birth = int(data_user[3])
if first_name.isnumeric() == True:
print("Error: the name should contain only letters.")
if last_name.isnumeric() == True:
print("Error: the last name should contain only letters.")
if len(phone_number) != 10:
print("Error: the phone number should be 10 digits.")
if phone_number[0] != "0":
print("Error: the first number should be 0.")
if phone_number.isnumeric() == False:
print("Error: the phone number most be a number.")
age = datetime.now().year - birth
if age<18:
print("Error: the year is not suitable.")
if age>100:
print("Error: the year is not suitable.")
else:
print("Name:",first_name,last_name, "\nPhone:",phone_number ,"\nBirth:", birth)
Aucun commentaire:
Enregistrer un commentaire