Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    \$\begingroup\$ You can change try:... and except:... to try:n=... and except:n='', saving you 10 bytes total \$\endgroup\$ Commented Oct 28, 2016 at 1:55
  • 1
    \$\begingroup\$ Why do you even have a try statement? The program spec says you will always get a positive integer. \$\endgroup\$ Commented Oct 28, 2016 at 12:46
  • \$\begingroup\$ @Shebang it should also return the latest comic when there is no input. I wasn't able to manage this case without carching the exception of input error. \$\endgroup\$ Commented Oct 28, 2016 at 13:53
  • 1
    \$\begingroup\$ @Joannes Why not use raw_input()? By default the user can press [Enter] and n will contain the empty string anyways. If you remove that try-except block and do t=u.urlopen(h+x+n).read() -> t=u.urlopen(h+x+raw_input()).read() you get it down to 274 bytes. \$\endgroup\$ Commented Oct 28, 2016 at 14:06
  • \$\begingroup\$ This no longer works, because xkcd image URLs use https. However, it's still valid, because it worked at the time of posting. To make it work now, change line 3 to start with h='https://' for +1 byte. \$\endgroup\$ Commented Jul 8, 2018 at 18:47