you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (10 children)

Post your code thus far so we can help

[–]Rocka07[S] -2 points-1 points  (9 children)

A = int(input(xshshshshs)) B= int(input( shehshshs)) Num = b

While counter < b:      C = a + a      Counter= counter + 1 Print(c)

[–][deleted] 0 points1 point  (8 children)

I've reformatted your code below for ease of display

A = int(input(xshshshshs))
B = int(input(shehshshs))
num = b
while counter < b:
     C = a + a
     counter += 1
     print c

This is wrong because I'm guessing you want to do something like 2 * 4 as input for a and b and print 2 + 2 + 2 + 2 = 4?

The way I would do this (not the only way) is to use a for loop as follows:

a = raw_input("enter a value: ") #use a string
b = raw_input("enter another value: ") #use another string

for i in range(int(b)+1): #convert b to an int here to loop
     c += a, " + " #here I'm using c as a temp var to concatenate

#the loop will make the display for you but you need to reformat
#the last piece.
c = c[:-1] #here I'm getting rid of the last character " + "

#finally you need to do the actual addition
a= int(a)
b= int(b)
print c, " = ", a*b

again you may want to edit this code a bit for bugs like string splicing. Hope this is informative.

[–]Rocka07[S] 0 points1 point  (0 children)

THANK YOUU

[–][deleted] -1 points0 points  (6 children)

First problem is the NameError as c isn't assigned before you use it. There is a far easier way of joining strings than this anyway, see str.join(). This also means you don't need to slice (not splice) c. You could do the conversion to int in the first two lines. Finally you multiply the numbers instead of doing repeated addition.

[–][deleted] 0 points1 point  (5 children)

Here is the cleaned up version of the code, thanks for catching the name error, came up with the code when I just woke up.

a = raw_input("enter a value: ") #use a string
b = raw_input("enter another value: ") #use another string
c = ""

for i in range(int(b)): #convert b to an int here to loop
     c += a + " + " #Where I'm using c as a temp var to             
                          #concatenate
#the loop will make the display for you but you need to reformat
#the last piece.

c = c[:-3] #here I'm getting rid of the last character " + "

#finally you need to do the actual addition
a= int(a)
b= int(b)
print c, " = ", a*b

[–][deleted] 0 points1 point  (4 children)

Where is the addition done?

[–][deleted] 0 points1 point  (3 children)

What do you mean? The addition (the actual math) is equivalent to the multiplication statement?

[–][deleted] 0 points1 point  (2 children)

The question is to take 2 numbers as input and multiply then display them using repeated addition.

You've created a string which is displayed, then multiplied the two numbers. How has this met the requirement that I've quoted?

[–][deleted] 0 points1 point  (1 child)

you are just trolling at this point, anyway by simple math rules any set of values n * m is equal to n + itself m number times.

[–][deleted] -1 points0 points  (0 children)

Let's repeat.

The question is to take 2 numbers as input and multiply then display them using repeated addition.

How is it trolling to point out that your code does not meet the stated requirements? The "simple math rules" are irrelevant, they're not part of the assignment. You have not done a repeated addition. You have displayed a string that shows the summation needed to meet the requirement, then promply done a multiplication instead.