• Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

How to assign the average and print as an integer

The instructions are to assign avg_owls with the average owls per zoo. Print avg_owls as an integer. However, the math keeps coming up wrong with the sample inputs. Even when I do the math by hand. The code is as follows.

Given sample inputs are 1 2 4

Your output Average owls per zoo: 4 Expected output Average owls per zoo: 2

I have written and can only alter the code avg_owls = int(num_owls_zooA + num_owls_zooB + num_owls_zooC / 3)

I don't understand how it's coming up with 4 when the actual math comes out to 2.333

What am I doing wrong?

jemcmorrow's user avatar

  • 1 Btw, you don't need to convert avg_owls to int , just pass it to print as it is.. –  Olvin Roght Commented May 11, 2021 at 14:10
  • Thank you. They're giving me a lot of information to take in. I don't know how they expect me to remember it all. –  jemcmorrow Commented May 11, 2021 at 14:34

6 Answers 6

Operator precedence, and the rules of maths, say that

will be calculated as

You need some brackets to get the result you want:

As an extra note, applying int to the result feels potentially wrong. It will cause it to always round down. For an average you would usually want to either keep it as a floating point value or at least round to the nearest value rather than always down.

Kemp's user avatar

  • Thanks! Math isn't my strongest suit. This is for a class. –  jemcmorrow Commented May 11, 2021 at 14:33

Two problems here. In pemdas or germdas, division comes before addition. SO you need parentheses around the addition. Also if you do int(4.3) you will get 4 . float will give you your desired output

also I suggest using f strings .

Buddy Bob's user avatar

  • You don't need to initialize avg_owls . Also it's better to stay with int while object of count is an owl, could you imagine three and half owls? :D –  Olvin Roght Commented May 11, 2021 at 14:19
  • Thank you. I'm stressed out. this is all new to me and I'm not the greatest at math either. –  jemcmorrow Commented May 11, 2021 at 14:32
  • 1 @OlvinRoght Don't worry. I thought about it all. My memory from my owl cutting past is coming back. I think I remember seeing a 1/16 nth of an owl. –  Buddy Bob Commented May 11, 2021 at 14:38
  • @BuddyBob, tough times –  Olvin Roght Commented May 11, 2021 at 14:40

This solution works as tested.

Flair's user avatar

This is the right answer...

total_owls = int(num_owls_A) + int(num_owls_B)

user22285039's user avatar

  • 1 Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center . –  Community Bot Commented Jul 28, 2023 at 15:50

avg_owls = (num_owls_zooA + num_owls_zooB + num_owls_zooC) / 3

num_owls_zooA = int(1)

num_owls_zooB = int(2)

num_owls_zooC = int(4)

That is the solution.

George's user avatar

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center . –  Community Bot Commented Sep 10, 2023 at 22:32

This is the correct one:

avg_owls = float((num_owls_zooA + num_owls_zooB + num_owls_zooC) / 3)

Sonny's user avatar

  • 2 Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center . –  Community Bot Commented Mar 13 at 22:10

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged python or ask your own question .

  • Featured on Meta
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • Announcing a change to the data-dump process
  • What makes a homepage useful for logged-in users

Hot Network Questions

  • I’m looking for a word that describes a decision being imposed on you unwillingly
  • How did Voldemort know that Frank was lying if he couldn't use Legilimency?
  • Zener instead of resistor divider on dc-dc converter feedback pin
  • Can a character forego one of their attacks if they have only one?
  • How artificial is the lack of 450%+/50t+ gearing on lesser 1x groups?
  • What is this font called and how to study it
  • GUI Interface for a command line program in C# Windows Forms
  • Has an aircraft ever crashed due to it exceeding its ceiling altitude?
  • Solution for a modern nation that mustn't see themselves or their own reflection
  • Contour Integration yielding wrong result
  • Can Falcon Heavy be used as a temporary replacement for the Falcon 9?
  • Ideas for cooling a small office space with direct sunlight
  • How were the alien sounds created in the 1953 War of the Worlds?
  • What standards did velocipedes have when they were invented?
  • What is the definition of \partial (∂) by using \DeclareMathSymbol
  • Can DHCP Server detect Windows version?
  • Does surviving an assassination attempt increase your chance of getting elected?
  • Was Macbeth considering murdering Duncan before Lady Macbeth encouraged him to?
  • Finding probability of winning in this game
  • Wikipedia states that the relativistic Doppler effect is the same whether it is the source or the receiver that is stationary. Can this be true?
  • If class B extends A, can we say that B depends on A?
  • Can only numeric username be used in Ubuntu 22.04.04 LTS?
  • When Éowyn secretly followed Théoden as Dernhelm, who was in charge of the Rohirrim?
  • Can a bad paper title hurt you? Can a good one help you?

assign total_owls with the sum of num_owls_a and num_owls_b

IMAGES

  1. Solved Assign total_owls with the sum of num_owls_A and

    assign total_owls with the sum of num_owls_a and num_owls_b

  2. [Solved] Assign total_owls with the sum of num_owls A and num owls_B

    assign total_owls with the sum of num_owls_a and num_owls_b

  3. Assign total_owls with the sum of num_owls_A and num_owls_B. The result

    assign total_owls with the sum of num_owls_a and num_owls_b

  4. Solved Assign total_owls with the sum of num_owls A and

    assign total_owls with the sum of num_owls_a and num_owls_b

  5. Solved Assign total_owls with the sum of num_owls_A and

    assign total_owls with the sum of num_owls_a and num_owls_b

  6. Solved Assign total_owls with the sum of num_owls_A and

    assign total_owls with the sum of num_owls_a and num_owls_b

COMMENTS

  1. Solved Assign total_owls with the sum of num_owls A and

    Step 1. Note: The solution comprises four distinct steps, with the complete code provided in the last step. ... Assign total_owls with the sum of num_owls A and num_owls_B. Sample output with inputs: 3 4 Number of owls: 7 1 test passed 3 num_owls_A = input () 4 num_owls_B - input 5 6 ""' Your solution goes here" 7 Al tests passed 9 num_owls_A ...

  2. How to assign the average and print as an integer

    The instructions are to assign avg_owls with the average owls per zoo. Print avg_owls as an integer. However, the math keeps coming up wrong with the sample inputs. ... total_owls = int(num_owls_A) + int(num_owls_B) Share. Improve this answer. Follow answered Jul 25, 2023 at 23:22. user22285039 user22285039. 1. 1. 1.

  3. Solved Assign total_owls with the sum of num_owls_A

    Question: Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: 3 4 Number of owls: 7 Use Python -- Type casting. There are 2 steps to solve this one.

  4. Solved Assign total_owls with the sum of num_owls_A and

    Question: Assign total_owls with the sum of num_owls_A and num_owls_B. Remember num_owls_A and num_owls_B need to be convertedto integers.Sample output with inputs: 34Number of owls: 7Learn how our autograder works544096.685116.qx3zqy7total_owls =0num_owls_A = input ( )num_owls_B = input ( )5|'' Your solution goes here '''78 ...

  5. [Solved] Assign total_owls with the sum of num_owls_A and num_owls_B

    Type casting to assign total_owls with the sum of num_owls_A and num_owls_B, the code will be: total_owls = int(num_owls_A) + int(num_owls_B) The entire source code will be. #variable to hold the total number of owls. total_owls = 0. #prompt the user to enter the number of owls A. num_owls_A = input()

  6. Answered: Assign total_owls with the sum of…

    Solution for Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: 3 4 Number of owls: 7 total_owls = 0 num_owls_A = input()…

  7. Strings numowlsA and numowlsB are read from input Assign

    Assign total_owls with the sum of num_owls_A and num_owls_B. Ex: If the input is:3 4 then the output is:Number of owls: 7 Note: Use the appropriate conversion function for each input. The input values like 3 or 4 should not explicitly be written in the code, since the values of num_owls_A and num_owls_B are randomly generated. total_owls = 0

  8. [Solved] Assign total_owls with the sum of num_owls_A and num_owls_B

    Q Here is the assignment question: Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: Answered over 90d ago Q Assign to avg_owls the average owls per zoo.

  9. Assign totalowls with the sum of numowlsA and numowlsB Sample

    Assign totalowls with the sum of numowlsA and numowlsB Sample ... Introduction to Scripting; Question; Anonymous Student. 1 year ago. Subject:Computer Science. Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: 3 4 ... Like. 0. Answer. 1 year ago. Here is the Python 3 code: total_owls = 0 num_owls_A = int ...

  10. Solved Assign total_owls with the sum of num_owls_A and

    Step 1. According to the description in question, it needs to provide Python code to find the sum of two inp... Assign total_owls with the sum of num_owls_A and num_owls_B. Remember num_owls_A and num_owls_B need ti to integers. Sample output with inputs: 34 Number of owls: 7 1 total_owls = 2 3 num_owls_A = input () 4 num_owls_B = input () 5 6 ...

  11. Assign total_owls with the sum of num_owls_a and num_owls_b.

    Next, you add these values together: 5 + 8 equals 13. This sum represents the total number of owls. Finally, you assign this sum to the variable "total_owls". Now, whenever you refer to "total_owls", it will represent the value 13. Remember to update the values of "num_owls_a" and "num_owls_b" if you need to calculate the sum again in the ...

  12. Answered: Assign total_owls with the sum of…

    Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: 3 4. Number of owls: 7. total_owls = 0.

  13. [Solved] Assign total_owls with the sum of num_owls_A and num_owls_B

    Q Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output for the given program: Number of owls: 7 num_ Answered over 90d ago Q Assign avg_owls with the average owls per zoo.

  14. Assign the variable total_owls with the sum of num_owls_a and num_owls

    To assign total_owls the sum of num_owls_a and num_owls_b, convert both to integers using int() and add them. For example, with inputs '3' and '4', total_owls would be 7. Explanation: To assign the variable total_owls with the sum of num_owls_a and num_owls_b, you need to ensure both variables are integers before performing addition. Here is a ...

  15. Assign total_owls with the sum of num_owls_A and num_owls_B. Sample

    To assign the value of total_owls as the sum of num_owls_A and num_owls_B in Python, you need to use type casting to convert the given numbers to integers and then perform the addition. First, convert num_owls_A and num_owls_B to integers using the int() function. Assign the converted values to new variables, let's say owls_A and owls_B.

  16. Here is the assignment question: Assign total_owls with the sum of

    Here is the assignment question: Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output with inputs: 3 4. Number of owls: 7. total_owls = 0. num_owls_A = input () num_owls_B = input () total_owls = int (sum ('num_owls_A + num_owls_B')) print ('Number of owls:', total_owls)

  17. Solved Assign total_owls with the sum of num_owls_A and

    Assign total_owls with the sum of num_owls_A and num_owls_B. Remember num_owls_A and num_owls_B need to be converted to integers. Sample output with inputs: 3 4Number of owls: 7. There are 2 steps to solve this one. Who are the experts? Experts have been vetted by Chegg as specialists in this subject.

  18. Solved ACTIVITY Assign total_owls with the sum of num_owls_A

    ACTIVITY Assign total_owls with the sum of num_owls_A and num_owls_B. Remember num_owls_A and num_owls_B need to be converted to integers. Sample output with inputs: 34 Number of owIs: 7 395644.2845392.qx3zqy 7 1 total_owls = 0 2 3 num_Owls_A = input( ) ...

  19. Assign total_owls with the sum of num_owls_A and num_owls_B. The result

    Assign total_owls with the sum of num_owls_A and num_owls_B. Remember num_owls_A and num_owls_B need to be converted to integers. Sample output with inputs: 3 4 Number of owls: 7

  20. [Solved] Assign total_owls with the sum of num_owls A and num owls_B

    Answer to Assign total_owls with the sum of num_owls A and num owls_B. Sample...

  21. Assign total_owls with the sum of num_owls_A and num_owls_B. Sample

    Assign total_owls with the sum of num_owls_a and num_owls_b. Sample output with inputs: 3 4 number of owls: 7. What can quantum computers do more efficiently than regular computers?

  22. Solved python Assign total_owls with the sum of num_owls_A

    Assign total_owls with the sum of num_owls_A and num_owls_B. Sample output for the given program: Number of owls: 7. There are 2 steps to solve this one. Who are the experts? Experts have been vetted by Chegg as specialists in this subject. Expert-verified. Step 1.