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

  • SEARCH
  • Home
  • 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 8566689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:42:44+00:00 2026-06-11T17:42:44+00:00

I have a program that prints multiplication tables. def print_tables(input): for i in xrange(1,11):

  • 0

I have a program that prints multiplication tables.

def print_tables(input):
    for i in xrange(1,11):
        print "%s x %s = %s" %(input, i, input*i)

user_input = raw_input("What do you want multiplied ten fold? ")

if(user_input.isdigit()):
    print_tables(int(user_input))

else:
    print_tables(user_input)

If the user enters a string "a", I would expect the output to be:

a x 1 = a
a x 2 = aa
a x 3 = aaa
a x 4 = aaaa
a x 5 = aaaaa
a x 6 = aaaaaa
a x 7 = aaaaaaa
a x 8 = aaaaaaaa
a x 9 = aaaaaaaaa
a x 10 = aaaaaaaaaa

Calling the print_tables function in both the if and else blocks does feel a bit redundant to me.

Is there a better way in Python to call the print_tables function regardless of the parameter type?

  • 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-11T17:42:46+00:00Added an answer on June 11, 2026 at 5:42 pm
    print_tables(int(user_input) if user_input.isdigit() else user_input)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a command line program that prints out a report such as: I
I have one application that prints messages from Test.exe in console .My java program
I have program that runs fast enough. I want to see the number of
I have a program that I want to distribute, without giving the source code
I have a (java) program that prints a line of hex numbers to stdout
I need some advice with the Java Print API. I have a program that
I have a Haskell program that shows a prompt and then accepts input from
I have a program that prints out the location of commas in a paragraph
I have a terribly uncomplicated test program that prints out the following numbers. i.e.
I have a program that executes various shell commands via system() and occasionally prints

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.