PDA

View Full Version : python Q (again)

flyingsliverfin
July 5th, 2009, 06:43 PM
if i want to have python read an input that is 18:00 and the input is all on one line how do i do that?
im trying to do this challenge: saving-time (http://codegolf.com/saving-time) but cant even get the input!

unutbu
July 5th, 2009, 07:09 PM
#!/usr/bin/env python
import sys
print(sys.argv[1])

LOL, according to Code Golf rules (http://codegolf.com/help)

You will be unable to import/require/include any modules or files in your solution. You have to write all the code yourself, and it has to be in the code file you upload.

I don't know how you are expected to read from stdin if you aren't allowed to import sys. :)

Apparently there is a way however, since there is a python leader board... :-k

croto
July 5th, 2009, 09:21 PM
You can get the input using python's built-in function raw_input.

unutbu
July 5th, 2009, 09:41 PM
Ah yes. That's right. The challenge says "18:00" will be supplied on stdin, not as an argument.

Thanks, croto. :)

flyingsliverfin
July 5th, 2009, 10:10 PM
whats stdin???? im confused...
whats the difference between stdin and just normal x = input()

Bodsda
July 5th, 2009, 10:49 PM
whats stdin???? im confused...
whats the difference between stdin and just normal x = input()

stdin is standard input, or the terminal.

time = raw_input("Enter time: ")

croto
July 5th, 2009, 10:57 PM
This is my 279 bytes solution:

b,Q,O,s=' ','o\n\n','o',raw_input()
h,m,c,i=int(s[:2]),int(s[-2:]),list(b*8+O+'\n o'+b*7+Q+' o'+b*13+Q+O+b*15+Q+' o'+b*13+Q+b*4+O+b*7+'o\n'+b*8+O),[8,22,40,59,77,92,102,84,63,43,26,14]
h%=12;m//=5
if h-m:c[i[h]],c[i[m]]='h','m'
else:c[i[h]]='x'
print reduce(lambda x,y:x+y,c)

still far from the 127 bytes winner!

flyingsliverfin
July 5th, 2009, 11:02 PM
holy cow

snova
July 6th, 2009, 01:38 AM
whats stdin???? im confused...
whats the difference between stdin and just normal x = input()

stdin refers to STanDare INput, which is usually a terminal (but can be redirected from a file from the shell).

input() is not the same as raw_input(). input() is equivalent to eval(raw_input()), and you should avoid its use.

flyingsliverfin
July 6th, 2009, 06:43 AM
oh... for the last couple months ive been using x = iinput()... ill start using raw_input

strange, just input() sounds more standard than raw_input

Can+~
July 6th, 2009, 06:55 AM
oh... for the last couple months ive been using x = iinput()... ill start using raw_input

strange, just input() sounds more standard than raw_input

In python3 raw_input() was dropped, and input() behaves like raw_input (only accepts strings). Same thing happened to xrange() and range().

flyingsliverfin
July 7th, 2009, 01:29 AM
ok good...whens python3 coming out?