So, I took mullet's suggestion (a couple pages back now) and decided to try and learn basic python by way of hangman.
Here is a newbie's attempt at hangman in python.
It meets all of mullet's specs, with the number of guesses excepted.
you run the program
python hangman.txt 'word or phrase for game'
Then just follow the instructions.
the one exception I made was that he wanted:
The user has 2x as many guesses as there are letters in the word to guess the word.
I won't tell you why I made the change, but if you play the game, you'll see soon enough.
I welcome any and all comments/suggestions/complaints about my program. Since I'm a newbie at this, I consider it all constructive criticism.
enjoy!
-nathan
p.s. oh yeah, and I think my next project will be a program that will keep track of a darts game of cricket for 2 or 3 players. we were playing darts the other night, and could've used it. so, if anyone else is up for it, that's my idea for a 'newbie challenge' maybe I'll get *****ious and learn some gui stuff too......
Yeah, works fine for me. Probably has to do with how DOS (I'm guessing) takes in command like arguments. I don't think it recognizes single quotes. Try double quotes, mrBen.
"You cannot invade the mainland United States. There would be a rifle behind each blade of grass." --Admiral Yamamoto, 1941
Originally posted by sasKuatch Yeah, works fine for me. Probably has to do with how DOS (I'm guessing) takes in command like arguments. I don't think it recognizes single quotes. Try double quotes, mrBen.
OK - this is a 5 minutes Python beginning (I'm at work - don't have any more time). It converts an IP address to a 32bit (unsigned) hex number.
It doesn't convert back yet, but it would take an IPv6 address
Code:
#!/usr/bin/python
ip="192.168.1.10"
hexip=[hex(int(x))[2:] for x in ip.split('.')]
for loop in range(len(hexip)):
if len(hexip[loop])==1:
hexip[loop]="0"+hexip[loop]
print "".join(hexip)
Nice Mr. Ben, but aren't split, len and range functions? I'll let it slide though. Aren't there any C/C++/JAVA programers who want to represent?
Ok, next. Now we have our IP address in unsigned long form and string form.
Let's say a user says that he/she wants to increment the value of part of the ip address by pointing at a position in the string and incrementing it there. (The ip string is now always XXX.XXX.XXX.XXX)
I.E. "192.168.001.010"
^
changes to
"202.168.001.010"
But when the user would select 1 from 192, it doesn't increment since 292 is out of range.
So here's kinda how it'll work,
OUTPUT: 192.168.001.010
INPUT: index of decimal user wishes to increment
OUTPUT: 202.168.001.010
In the background, you'll have the IP address stored in a unsigned long/int (32-bit) and only convert to string to output.
The REAL challange: Write it in a few lines as you can without using ANY functions(other than those you create)
P.S. Getting these challanges from portions of code I write at work, in case someone might think is hw or something. I did this the actual work, not i/o, in 6 lines of code.
[edit]speaking of work, maybe i should do some...[/edit]
if (i_forgot && this_is_about_code)
language = c++;
Originally posted by tecknophreak Nice Mr. Ben, but aren't split, len and range functions? I'll let it slide though.
Yeah, but so are hex and int. But they are all builtins, so it's not like he's using a library or something.
Also, mrBen, yours wouldn't take an ipv6 address and do it because those use ':' as the separator and not '.' I actually think I posted the code to do just this very challenge on this board (or somewhere) not too long ago.