01-11-2008, 07:22 AM
Canaris Wrote:I tested your program and not sure if it's the way you want but when I type: "buy" when it says "I have a 'sword' and a 'shield' for sale! Which would you like to 'buy' some sir?" it prints "Care to buy anything else?". Shouldn't that be only after the purchase?
Nice start for only having learned for 6 hours. Keep it up
I'm not expert programmer or anything just used to try out some stuff for fun like you are doing now. Anyway, If you are still improving it to learn here's some food for the thought.
1) Remove some of the unneeded variables. Your while loops use boolean variables to break out of them. You can clean it up a bit by just making it endless loop and breaking out using break statement whenever needed. No change in functionality. Just easier for the reader of your code.
Code:while 1:
if selection == 1:
# do stuff here
break
elif selection == 2:
# do some other stuff here
break
2) Error checking for user input. What if user decides to type for example "plaa" to a question that accepts integer variables (for example the first question)? Program goes nuts. Exceptions are easy way to handle those situations more gracefully and have your program deal with the situation:
Never trust users of your program to do the intended thingCode:try:
selection = int(raw_input("Please choose a reward 1 or 2.\n"))
except:
print "Only numerical values accepted!"
More on topic: Nasir said code like this would take max 15mins to write. I'm sure any of the devs that are working/worked on INX can do that. Can't really compare between what more experienced devs like Maka, Nasir or Rob do and code that galens wrote. Difference in amount of experience is huge.
Ya know, I was reading on try and except later in the morning, then I passed out from lack of sleep. I didn't quite grasp it. Now I get it, instead of it printing any error and exiting the program, its more or less another if statement, except, if raw_input = null, non int or non str, it prints a repetative message. I could squeeze you till your eyeballs poop out. ^_^
I'm going to try and fix, plus add a ton more features with narration.
I appreciate it.