Code Club – testing input

Once you have code working nicely, it is a good idea to add in error checking so that when asking for user input, what is put in to the program matches what is required.

We can ask a user for a numerical value so we know how many times to repeat the loop. How do we test for this.

letter = rawinput(“Enter your name “) i = letter.isalpha() while i != True: print(“Input MUST use letters”) letter = rawinput(“Name “) i = letter.isalpha() print letter

In this example, the user is asked to enter their name, this is stored and checked that is is actually a alphabetical character a-z or A-Z.

Tags

#CodeClub,#Python.#Programming,#UserInput,#Testing


MastodonPeertubeJoin Mastodon

Donate using Liberapay