I'm looking for help on the question:
So far my code has gotten me far enough to return the right answer but also the restultant multiplication along the way, i.e.: (1, 2, 2, 8, 8, 48). Can anyone reshuffle or redo the code so it just outputs the answer only, thanks in advance!
counter=1
product=1
userinput=int (input ("What number: "))
for counter in range (1, userinput):
if counter%2==0:
product=int (counter*product)
counter=counter+1
else:
counter=counter+1
print (product)
that's because print
is executed on every iteration, you need to execute it only after the loop ends, which means print
must have the same indent level as the loop,
counter=1
product=1
userinput=int (input ("What number: "))
for counter in range (1, userinput):
if counter%2==0:
product= int(counter*product)
print(product)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With