Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:04:02+00:00 2026-06-09T14:04:02+00:00

#/usr/bin/python2.4 -tt import sys def mult_table(x,y): for i in range(1,y+1): for n in range(1,x+1):

  • 0
#/usr/bin/python2.4 -tt

import sys

def mult_table(x,y):
  for i in range(1,y+1):
    for n in range(1,x+1):
      if n == 1:
        print i*n,
      elif n == x:
        print repr(i*n).rjust(3)
      else:
        print repr(i*n).rjust(3),

mult_table(12,3)
sys.exit(0)

I submitted this short program to CodeEval. Its only job is to make a multiplication table. The problem is that it should not have any trailing whitespace and when I submitted it the last line has a space after the 36. I tested myself, and I don’t have this problem. What is going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:04:04+00:00Added an answer on June 9, 2026 at 2:04 pm

    Your code adds a space for mult_table(1,1) not for mult_table(12,3).

    So you need to fix your if n == 1 case (to also check n == x, as you do later in the code).

    I would do this a bit differently, so that the heart of mult_table is something like:

          if n == 1:
            print i*n,
          else:
            print repr(i*n).rjust(3),
    

    And then just print your newline in the outer for loop.

    Take-home: Test your boundary conditions! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#!/usr/bin/python2.4 import logging import sys import doctest def foo(x): >>> foo (0) 0 print
#! /usr/bin/env python import os import stat import sys class chkup: def set(file): filepermission
#!/usr/bin/python import wx import os import sys class MyFrame(wx.Frame): def __init__(self, parent, id, title):
okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,
I have this code: #! /usr/bin/python import sys, string def findAll(search, fh): count =
Firstly, here's my script: #!/usr/bin/python import sys, os sys.path.append('/home/username/python') sys.path.append(/home/username/python/flup) sys.path.append(/home/username/python/django) # more path
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter import twitter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent=parent
I have the following code: #!/usr/bin/env python import sys from PyQt4 import QtGui, QtCore
Simple code demonstrating the problem: #!/usr/bin/env python import sys from PyQt4.QtCore import QObject, SIGNAL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.