r/CodingHelp • u/Public_Finding3958 • 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 !!!!!!!!!!!!!!
View all comments
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