Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python [Beginner] Why is this not correct?

Khalon

Coder
Python:
#Add the input number 4 times. Ex. 3+3+3+3
#If the input is 3, the output will be 12

num = int(input("Num: "))

for x in range(2):
    num += num

print(num)

Using an app called "Easy Coder" and
for some reason, the code above is not correct.

Is there a better way to do this? so the actual process of the code is("3+3+3+3) and not(3+3) + (3+3)
 
Solution
Adding the number to itself 4 times is the same as multiplying the number by 4, like so:

Python:
num = int(input("Enter a number: "))

print(num * 4)
Sorry, I forgot to mention, that this is an exercise related to looping. The task:" Write a program that uses a for loop to calculate any number X 4. Hint - Add the number to a variable 4 times.

But I think I got it 🙂

Python:
num = int(input("Num: "))
total = 0

for x in range(4):
    total += num

print(total)
Adding the number to itself 4 times is the same as multiplying the number by 4, like so:

Python:
num = int(input("Enter a number: "))

print(num * 4)
Sorry, I forgot to mention, that this is an exercise related to looping. The task:" Write a program that uses a for loop to calculate any number X 4. Hint - Add the number to a variable 4 times.

But I think I got it 🙂

Python:
num = int(input("Num: "))
total = 0

for x in range(4):
    total += num

print(total)
 
Solution
Back
Top Bottom