In Perl, you'd say:
($a, $b) = ($b, $a);
which must be even cleverer than Python:p
Printable View
In Perl, you'd say:
($a, $b) = ($b, $a);
which must be even cleverer than Python:p
Is this a joke?Quote:
Originally posted by o0zi
In Perl, you'd say:
($a, $b) = ($b, $a);
which must be even cleverer than Python:p
Sure hope so:)
Burninating the peasants,Quote:
Originally posted by dchidelf
Go ahead and burninate the countryside.
Burninating all the peoples,
IN THEIR THACHED-ROOFED COTTAGES!
thached-roof cottages
And the Trogdor comes in the NIIIGHT!
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:
I won't tell you why I made the change, but if you play the game, you'll see soon enough.Quote:
The user has 2x as many guesses as there are letters in the word to guess the word.
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......
OK - played the game now. Couple of comments to make:
1. It only accepts a single word, not a whole phrase - if you put in something like 'star wars' it only takes the first word.
2. It includes the quotes you put in - ie from the above it will actually take 'star as the word
My suggested solution would be to start the game by asking them to enter a word or phrase, rather than using it as an argument for the program.
Other than that, good job! :D
Mr. Ben,
when I play it on my computer, it seems to work as expected
for example:
and the final line would be:Quote:
[friedn@localhost programming]$ python hangman.txt 'some stuff'
**** *****
Please enter a guess:
I believe you that it's different on your machine, but I don't know why. Any ideas on why?Quote:
Please enter a guess: f
some stuff
perplexing...........
-nathan
Probably because I'm running it at work under Windows........
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.
Aha!Quote:
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.
That worked. :D
I retract all my previous comments.
Here's another answer to that square question I asked a while ago:
Code:#include <iostream>
int main() {
int square(1), diff(3);
while (square < 10000) {
std::cout << square << std::endl;
square += diff;
diff += 2;
}
}
Ok, new challange, this one is basically a little parser with little to do with math. Mostly strings.
Convert an IP address to a unsigned long(32-bit) and back.
Criteria:
1. The only functions you can use, you have to create yourself, no using libraries.
2. The IP address can be given to you in any format, doesn't have to be XXX.XXX.XXX.XXX, it can also be XXX.XX.XX.XXX or anything else.
I hope that's enough to discourage any "cheaters" ;)
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]
Quote:
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.