The Programming Skills Survey

You have been tasked with creating a Python program that generates a survey about programming preferences and skills. Your program will have to:

Ask the user a series of questions about their programming experience.
Validate the user’s input for each question of the survey using different validation checks.
Store the responses in a text file (CSV file format).

Validation Checks in Python


The following tabs will show you how to implement different validation checks using Python.
Presence CheckType CheckRange CheckLookup CheckCharacter CheckLength CheckTry again!

Input Validation: Presence Check


A presence check is useful to ensure an input is not empty.

name = input("Enter your name:").strip() 

if name=="":
    print("Empty name!")
else:
    print("Thank you!")


Input Validation: Type Check – Integer?


A type check ensures the input is of the correct data type (e.g. check that te user enters an integer value when required to do so).

number = input("Type a number:")

if number.isdigit():
    print("This is a number")
else:
    print("This is not a whole number")


Input Validation: Range Check


A range check is used to ensure an input falls within a numerical range, between a minimum value and a maximum value).

number = int(input("Type a number between 1 and 5:"))

if number>=1 and number<=5:
    print("Valid number")
else:
    print("Invalid number")


Input Validation: Lookup Check


A lookup check ensures the input provided matches one of a predefined set of valid options.

drive = input("Can you drive?").lower()

if drive in ["yes","no"]:
    print("Valid answer")
else:
    print("Invalid answer")


Input Validation: Character Check


Format checks/Character checks: can be used to ensure the input is following a specific format or include specific characters (e.g. a valid e-mail address should include an @ character).

email = input("Type your e-mail address:")

if "@" in email:
    print("Valid e-mail address")
else:
    print("Invalid e-mail address")

postcode = input("Type your postocode:").upper()

if postcode[0] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and postcode[1] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and postcode[2] in "123456789":
    print("Valid postcode")
else:
    print("Invalid postcode")

Input Validation: Length Check


Length checks are used to validate the length of the input (e.g. minimum or maximum number of characters).

password = input("Type a password:")

if len(password)>=8:
    print("Valid password")
else:
    print("Invalid password")


Try Again! Using a While Loop:


Using a while loop within your validation checks instead of an if statement will allow the user to have multiple attempts if needs be to enter a valid input.

name = input("Enter your name:")

while name=="":
    print("You must enter your name! Please try again!")
    name = input("Enter your name:")

print("Welcome " +  name)

You can investigate more advance approaches to implement validation subroutines on this blog post.

List of questions for the survey

Your survey will consist of the following questions and validation checks:

Question Validation check
1. What is your name? Presence Check – User input cannot be an empty string
2. What is your e-mail address?” Format Check – Must be contain an @ character
3. How many years have you been programming? Type Check / Range Check – Must be a positive integer value.
4. What is your favourite programming language? Lookup Check – Must be one of [“Python”, “JavaScript”, “Java”, “C++”, “Other”]
5. Describe your programming skills in a few words. Length Check – Must be at least 10 characters
6. How would you rate your programming skills using a score value between 1 (Beginner Level) and 5 (Advanced Level)? Range Check – Must be a number between 1 and 5

Python Code

We have stared the survey for you but have only completed the code for the first question. Complete the code below to ask all 6 questions and implement the required validation checks for each question. You will also need to add some code to save all the survey results in a text file (CSV file format).

Extension Ideas:

Complete your code to:

    Add more questions with other validation checks.
    Allow users to view their responses before saving them to the file.
    Provide an option to retake the survey or correct specific answers.

Did you like this challenge?

Click on a star to rate it!

Average rating 3.5 / 5. Vote count: 26

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!