0

I am new the python, so forgive me if this is such a basic problem. I am building a VERY simple data collection program and of course I need to get it to loop at certain times based on user input.

import sys
 
sys.stdout.write("Enter your name: ")
employee_name = sys.stdin.readline().strip()

if (employee_name==""):
    sys.stdout.write("You must enter your name!")
   
else:
    sys.stdout.write("Thank you\n")
    sys.stdout.write("Hello, " + employee_name +"!\n")
    sys.stdout.write("What is your date of birth? ")
 
employee_dob = sys.stdin.readline().strip()
 
if (employee_dob==""):
    sys.stdout.write("Please enter a valid date of birth")
 
else:
    sys.stdout.write("Thank you for telling us you were born on " + employee_dob + ", " + employee_name + ".\n")
    sys.stdout.write("Are all of these details correct? [y/n]\n")
 
correct_details = sys.stdin.readline().strip()

employee_list = []
 
if (correct_details=="y"):
    employee_list.append(employee_name + " " + employee_dob)
    sys.stdout.write("Thank you for confirming! Your new employee details are as follows: \n")
    sys.stdout.write(*employee_list)
    sys.stdout.write("\nDo you want to to enter new employee details? [y/n]\n")

new_details = sys.stdin.readline()

I want the system to loop if no name is entered where the "You must enter your name" is displayed, as well as if theres no DOB entered, and finally at the end where it asks if the details are correct and if they want to enter more details.

I have played around with the "while true" code however I have not been successful in my endeavours.

  • 2
    Is there any specific reason for using `sys.stdin.readline` and `sys.stdout.write` instead of `input` and `print`? – matszwecja Sep 09 '22 at 07:06

0 Answers0