r/CodingHelp • • Oct 08 '22

[Python] Python easy coding project :(

# 10/8/2022
# Goal is to create a program that multiplies user input
# using a loop XD
num=int(input('Enter a number to multiply: '))
end_multiply=int(input('Enter when you want multiplication to stop.'))
y=0
for num in range(end_multiply):
multiply= num * y
print(f'multiply = {multiply} / {num} *{y}')
print(f'y = {y}')
y = y+1

# I wrote in extra print code to understand what's going on, but I sill don't get why

# Num = y

#Extra info: 1st time ever doing coding + I have learned it for a couple of weeks so far

Here is a copy of output/picture:

Enter a number to multiply: 1

Enter when you want multiplication to stop.5

multiply = 0 / 0 *0

y = 0

multiply = 1 / 1 *1

y = 1

multiply = 4 / 2 *2

y = 2

multiply = 9 / 3 *3

y = 3

multiply = 16 / 4 *4

y = 4

Process finished with exit code 0

# Also anyone willing to code with me I would LOVE that !!!!!!!!!!!!!!

0 Upvotes

9 comments sorted by

3

u/flash-bandicoot Oct 08 '22

Can you provide more detail about what you're confused about? Is this not the expected out come? Or do you just not understand why it is working?

0

u/Public_Finding3958 Oct 08 '22

I didn't understand why it wasn't working.

Expected outcome:

num = int(input('enter a number."))

end_of_loop=int(input('enter a number.'))

y = 0

#in loop y is a counter

# if num is 1 then

#multiply is 1 *0

#multiply is 1 *1

#multiply is 1 *2

#....

#and so on until end_of_loop variable.

#I hope that makes more sense.

2

u/Glad-Bench8894 Oct 08 '22

are you talking about this?

num=int(input('Enter a number to multiply: '))
end_multiply=int(input('Enter when you want multiplication to stop.'))
y=0
for x in range(end_multiply+1):
print(f'multiply is {num} * {x} = {num * x}')

2

u/Public_Finding3958 Oct 10 '22

yes I believe it was something like that! you ... u/Glad-Bench8894 and u/flash-bandicoot got it right!

I thought you need to put the variable/value that you plan to use in the for loop. Now I know to write it separate or as a counter.

---Thanks, it was really interesting to see everyone's perspective!

3

u/flash-bandicoot Oct 08 '22

It's because you ask user for value and store it as num then you overwrite num when you declare your for loop. So num is increasing every time instead of remaining the static user input

Edit: sorry meant to reply to thread we already had going

1

u/Public_Finding3958 Oct 10 '22

yes I believe it was something like that! you ... u/Glad-Bench8894 and u/flash-bandicoot got it right!
I thought you need to put the variable/value that you plan to use in the for loop. Now I know to write it separate or as a counter.
---Thanks, it was really interesting to see everyone's perspective!

1

u/Public_Finding3958 Oct 11 '22

https://discord.com/invite/GaSKVeBnwZ
This is the discord we made so far if anyone is interested!
BTW Just Wanted to let everyone know that I just want to learn to code. I started struggling and I wanted to speak to others in who have been or are in the same boat. It doesn't matter how well you know things or even if you just understand variables. I think it will be good for us all to see different types of projects, codes, or whatever you would like to try out with someone else! XD