Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7035973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:22:06+00:00 2026-05-28T01:22:06+00:00

I am working on a program that needs to do the following: Write a

  • 0

I am working on a program that needs to do the following:

Write a script that asks a user for a number. The script adds 3 to that number. Then multiplies the result by 2, subtracts 4, subtracts twice the original number, adds 3, then prints the result.

Here is my first solution:

#Prompt user for number
 number = input("Input a number")

#Print out the solution
 print number + 3 * 2 - 4 - (number * 2) + 3

And here is my second solution:

#Prompt user for number
 number = input("Input a number ")

#Add 3 to number
 print "Let's add 3"
 number1 = number + 3
 print number1

#Multiply by 2
 print "Let's multiply by 2"
 number1 = number1 * 2
 print number1

#Subtract 4
 print "Let's subtract 4"
 number1 = number1 - 4
 print number1

#Subtract twice the original number
 print "Let's subtract the original number twice!"
 number2 = number + number
 number1 = number1 - number2
 print number1

#Add 3
 print "...And finally, we add 3"
 number1 = number1 + 3
 print "Our sum is", number1

Which solution is correct, or are they both incorrect?

I know this is very basic, but I am learning to Program. I thought I would try out 2 different ways of writing this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:22:06+00:00Added an answer on May 28, 2026 at 1:22 am

    Just add a pair of parentheses to your first version to correct it:

    print (number + 3) * 2 - 4 - (number * 2) + 3
    

    Otherwise, 3 * 2 would be evaluated with higher precedence than the additions and subtractions.

    Note that the output does not depend on the number at all. Simplifying the expression shows that

    print 5
    

    does the same as the code above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program that needs to create a multiple temporary folders
I am working on a php program that needs to store many Event objects
I'm working on an app that needs to intercept when a program tries to
I'm working on a program that will need to delete a folder (and then
I'm working on a program that needs to be able to load object-properties from
I have a Python script that needs to execute an external program, but for
I need to restart the program that im working on after an update has
I'm working on a program that processes many requests, none of them reaching more
I'm working on a program that searches entire drives for a given file. At
I'm working on a program that uses PHP's internal array pointers to iterate along

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.