Jump to content

A small game, applied the same theories from Coding 101


G+_Ayesh Rodz
 Share

Recommended Posts

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

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

 Share

×
×
  • Create New...