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 660431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:09:18+00:00 2026-05-13T23:09:18+00:00

I am a student in a concepts of programming class. The lab is run

  • 0

I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real quick and then argued with him for 10 minutes that it was bad math. It was, 4 * -5 does not equal 20, it equals -20. He said that he really dosen’t care about that and that it would be too hard to make the prog handle the negatives anyway. So my question is how do I go about this.

here is the prog I turned in:

#get user input of numbers as variables

numa, numb = input("please give 2 numbers to multiply seperated with a comma:")

#standing variables
total = 0
count = 0

#output the total
while (count< abs(numb)):
    total = total + numa
    count = count + 1

#testing statements
if (numa, numb <= 0):
    print abs(total)
else:
    print total

I want to do it without absolutes, but every time I input negative numbers I get a big fat goosegg. I know there is some simple way to do it, I just can’t find it.

  • 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-05-13T23:09:19+00:00Added an answer on May 13, 2026 at 11:09 pm

    Perhaps you would accomplish this with something to the effect of

    text = raw_input("please give 2 numbers to multiply separated with a comma:")
    split_text = text.split(',')
    a = int(split_text[0])
    b = int(split_text[1])
    # The last three lines could be written: a, b = map(int, text.split(','))
    # but you may find the code I used a bit easier to understand for now.
    
    if b > 0:
        num_times = b
    else:
        num_times = -b
    
    total = 0
    # While loops with counters basically should not be used, so I replaced the loop 
    # with a for loop. Using a while loop at all is rare.
    for i in xrange(num_times):
        total += a 
        # We do this a times, giving us total == a * abs(b)
    
    if b < 0:
        # If b is negative, adjust the total to reflect this.
        total = -total
    
    print total
    

    or maybe

    a * b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a blind student who's taking a required UI class. One of the assignments
Recently a teacher said PHP isn't a real programming language, but only gave, in
Programming Student here...trying to work on a project but I'm stuck. The project is
I am a student studying software development, and I feel programming, in general, is
I'm a Engineering student and I'm attending a Database and Information Systems class this
I am a college student at a school that teaches mainly in Java. One
I'm a computer science student finishing up my second semester of programming classes. I've
I am a CS student trying to grasp some C++ basic concepts. I am
Say I have a Student table, it's got an int ID. I have a
I'm a CompSci student, and fairly new at C#, and I was doing a

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.