School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,215 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,582 people online right now. Registration is fast and FREE... Join Now!




Help with Name == function and other questions

 

Help with Name == function and other questions

baseballplayinty

6 Sep, 2009 - 11:14 AM
Post #1

New D.I.C Head
*

Joined: 6 Sep, 2009
Posts: 1

Alright so I just started writing a D & D type game and I wanted to let the users create their own names that they may use.

My two problems are kinda noobish to the language as I am really rusty from not coding in a year. Anyways

CODE

name1 = raw_input
if name1 ==


My first problem is I cannot think of how to if the user chooses a blank name to say try again. Not as in print but as in restart the name1 process telling them to try again...

If you wanted to delay a process for X amount of time how would you do so?

My third question is there any Artificial Intelligence examples that I could work off of? I am in dire need of it and have come up with blanks.

Hopefully this all makes sense and I haven't broken any rules :-)

Regards,
Tyler

This post has been edited by baseballplayinty: 6 Sep, 2009 - 11:16 AM

User is offlineProfile CardPM
+Quote Post


shadhin

RE: Help With Name == Function And Other Questions

6 Sep, 2009 - 02:54 PM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 434



Thanked: 19 times
Dream Kudos: 3650
My Contributions
The following example demonstrates how to check empty string. You can also loop through to perform the process for a certain number of times-
CODE

attempt=0
while attempt<5:
    x=raw_input("Enter something:")
    if x=="":
        print "You Have Entered Empty String. Try again!"
        attempt +=1
    else:
        print "Welcome"
        break


User is offlineProfile CardPM
+Quote Post

code_m

RE: Help With Name == Function And Other Questions

8 Sep, 2009 - 03:19 PM
Post #3

D.I.C Head
**

Joined: 21 Apr, 2009
Posts: 124



Thanked: 8 times
My Contributions
Just check the string itself !

python

name = ""
while len(name) == 0:
name += raw_input("Input name: ")


no need for an extra variable biggrin.gif
User is offlineProfile CardPM
+Quote Post

girasquid

RE: Help With Name == Function And Other Questions

10 Sep, 2009 - 02:14 PM
Post #4

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,648



Thanked: 59 times
Dream Kudos: 825
My Contributions
You could also use the built-in None instead of calling len() on name all the time:
CODE

>>> name = None
>>> while not name:
...  name = raw_input("Enter name: ")
...
Enter name:
Enter name:
Enter name: asdfas

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:02PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month