• The Amara On Demand team is looking for native speakers of German, Japanese, Korean, Italian, Hindi and Dutch to help with special paid projects
Apply here Hide

## ← Rounding Numbers - Intro to Computer Science

• 3 Followers
• 32 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=8vnR6H8euXY" data-team="udacity"></div> ``` 7 Languages

Showing Revision 6 created 05/24/2016 by Udacity Robot.

1. [Male] For the last question in Homework 1,
2. you're going to solve the problem of how to round numbers,
3. and this is going to require using a new Python function we haven't
4. introduced yet in lecture, but you'll be able to figure it out
5. as part of this homework problem.
6. But it's a pretty tough question, so that's why it has 2 gold stars.
7. The new function that you'll use is the str function.
8. The str function takes as input any number,
9. and it turns that number into a string, so the output of str
10. applied to a number is a string that represents the number that was passed in,
11. so if we evaluated str on the number 89,
12. what that evaluates to is the string containing the characters 8 and 9.
13. So it's a string that looks like the number that was passed in,
14. but instead of being a number, now it's a string.
15. If you understand str, you'll be able to solve this question.
16. Your goal for this question is given a variable x,
17. so at the beginning of your code, x has been initialized to store the value
18. of any decimal number.
19. What your code should do is print out the nearest whole number to x.
20. So here's a few examples.
21. If the value of x is 3.14159,
22. what your code should print out is 3.
23. If the value of x is 27.63,
24. your code should print out 28.
25. And to keep this a little simpler, you can assume that the value of x
26. is not negative.
27. This is going to require you to combine several things
28. that you've seen in Unit 1.
29. The only new thing that you need to solve this is the str function
30. that we've just explained.
31. Everything else that you need to solve this is something that you already know
32. from Unit 1.