G+_Ayesh Rodz Posted April 19, 2014 Share Posted April 19, 2014 A small game, applied the same theories from Coding 101.. Hope there may be some bugs. And I was wondering whether is there any method where we can sanitize a variable to accept only characters & ignore all the others such as numbers and symbols. It might be useful to sanitize "Name" variable. :) https://github.com/ashuz/Coding101/blob/master/Game.py Link to comment Share on other sites More sharing options...
G+_L I Posted April 19, 2014 Share Posted April 19, 2014 There is an isapha() function so you could do something like this: Name = raw_input("What is your name?: ") while not(Name.isalpha()): Name = raw_input("Invalid name. What is your name?: ") Of course this will prevent names with hyphens and possibly names with accents/umlauts/etc. More than likely you'd have to write your own data sanitizing function to meet the specific needs of your program. Link to comment Share on other sites More sharing options...
G+_Ayesh Rodz Posted April 19, 2014 Author Share Posted April 19, 2014 thanks! :) I've changed accordingly.. Link to comment Share on other sites More sharing options...
Recommended Posts