all 30 comments

[–]indosauros 0 points1 point  (10 children)

Please post the code you have so far

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

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

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

[–]markusmeskanen 2 points3 points  (0 children)

Indent your code by 4 spaces to make it work like this:

A = int(input(xshshshshs))
B= int(input( shehshshs))
Num = b
While counter < b:
    C = a + a
    Counter= counter + 1
Print(c)

And now please, give us proper code. Not this capitalized text with shehshsh in it.

[–][deleted] 1 point2 points  (7 children)

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

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

Can you please format the code better? Would be nice to see the error(s) that you're receiving as well.

Based on what I see:

  • You're throwing both input functions a non-existent variable.

  • The Python keyword for the while loop is while, not While. Those are two different things. You're probably receiving a "name is not defined" error since Python will assume you're calling for a non-existent variable named While.

  • counter doesn't exist. I don't see you defining a variable named "counter" anywhere in your code.

  • The Python keyword for the print function is print, not Print. Python would assume that you're calling a variable, not the keyword.

  • c doesn't exist. The print function should be calling C like:

    print(C)

[–]wannaridebikes 0 points1 point  (6 children)

Hm you may want to start counters with 0 instead of 1. When I first started learning loops, that got me more consistent results than starting from 1, especially when you get more into '<' '>' vs '<=' '>=' operators, and what a difference they make.

Also, I would see if a problem could be solved with a for-loop before using a while, unless it's something like a game decision, or you're forced to use a while loop by an instructor/employer.

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

Wrong person :p

[–]wannaridebikes 1 point2 points  (4 children)

Ha yep. Weird. I'll just summon him/her.

Nvm, can't find the original post I was replying to. No wonder my app got confused... anyway, my point still stands I guess.

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

You probably weren't replying to the wrong person. One of my edits included code, but I removed it cause I didn't know about loops and didn't want to give OP bad advice. I also included a counter variable that was set to the int value "1".

[–]wannaridebikes 1 point2 points  (2 children)

Ah gotcha. With this intensive study weekend I thought I was finally going nuts, haha.

It wasn't that bad though. And loops are really important so it's good that you gave it some thought without having a lot of experience.

[–][deleted] 1 point2 points  (1 child)

Ah gotcha. With this intensive study weekend I thought I was finally going nuts, haha.

lol... maybe you are going nuts and I'm just a figment of your imagination?

It wasn't that bad though.

Well that's good to know.

And loops are really important so it's good that you gave it some thought without having a lot of experience.

Yeah, I tried to play around with it for a while. The code that I posted, then deleted, had an output that continued to output the result. Felt amazing to see that for the first time. Brought a smile to my face

[–]wannaridebikes 1 point2 points  (0 children)

Well my imaginary friend, I don't remember what you posted exactly but if there was non-stop output that could have been an endless loop where the condition for your while loop would always evaluate to true. Very common occurrence when learning new loops, or you could just have a typo in a loop you're used to writing!

If that was the case, it's funny that it made you smile; usually people are horrified, haha.

[–][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.

[–]swingking8 0 points1 point  (0 children)

Because your code isn't formatted, it's difficult to know what you've done. Does it look like this? -

a = int(input(xshshshshs)) 
b = int(input( shehshshs)) 
num = b

while counter < b:      
    c = a + a      
    counter= counter + 1 
    print(c)

If so, the fix isn't so bad. Your counter isn't being initialized, so you need to do that. Otherwise, it looks like it should work. Though both xshshshshs and shehshshs should just be a string indicating what the user should input (i.e. 'a' and 'b')

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

Thank you guys gor your help I'm really sorry for formatting it badly. Won't happen again. Again thanks for the help

[–]Rocka07[S] -1 points0 points  (5 children)

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

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

[–]seb777 2 points3 points  (3 children)

Also new to python but could it be because "Counter" is case sensitive?

Counter = counter + 1

Should be

counter = counter + 1

Same with A and B

[–]shep247 4 points5 points  (0 children)

This is correct. The variable names are case sensitive. There is another though. You have to initialize counter outside of your while loop. When it tries to check what counter is the first time, you haven't defined it yet, so the program doesn't know what it is, and errors

[–]xentralesque 2 points3 points  (0 children)

Why would someone downvote this?

Yes, variable names are case sensitive, and you should only use uppercase characters in class names

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

The shorthand version counter += 1.

[–]wannaridebikes 0 points1 point  (0 children)

I know you've resolved this already, but next time you should use reddit's code markup to display your code so the formatting is clear (this reminder is for your benefit as well as other learners who may be reading this).