title: Round to whole numbers without using conditional statements in Python - Logic
body: <p>I'm taking a Python course at Udacity, and I'm trying to work this out for myself without looking at the answer. Perhaps you can give me a hint for my logic?</p>
  
  <p>Below are the instructions and what I have so far. We haven't learned conditional statements yet, so I can't use those. We've only learned how to assign/print a variable, strings, indexing strings, sub-sequences, and .find. They just introduced the str command in this final exercise.</p>
  
  <pre><code># Given a variable, x, that stores the 
  # value of any decimal number, write Python 
  # code that prints out the nearest whole 
  # number to x.
  # If x is exactly half way between two 
  # whole numbers, round up, so
  # 3.5 rounds to 4 and 2.5 rounds to 3.
  # You may assume x is not negative.
  
  # Hint: The str function can convert any number into a string.
  # eg str(89) converts the number 89 to the string '89'
  
  # Along with the str function, this problem can be solved 
  # using just the information introduced in unit 1.
  
  # x = 3.14159 
  # &gt;&gt;&gt; 3 (not 3.0)
  # x = 27.63 
  # &gt;&gt;&gt; 28 (not 28.0)
  # x = 3.5 
  # &gt;&gt;&gt; 4 (not 4.0)
  
  x = 3.54159
  
  #ENTER CODE BELOW HERE
  
  x = str(x)
  dec = x.find('.')
  tenth = dec + 1
  
  print x[0:dec]
  </code></pre>
  
  <p>////</p>
  
  <p>So this gets me to print the characters up to the decimal point, but I can't figure out how to have the computer check whether "tenth" is > 4 or &lt; 5 <em>and</em> print out something according to the answer. </p>
  
  <p>I figured I could probably get far enough for it to return a -1 if "tenth" wasn't > 4, but I don't know how I can get it to print x[0:dec] <em>if</em> it's &lt; 5 and x[0:dec]+1 if it's > 4. </p>
  
  <p>:/</p>
  
  <p>Could someone please give me a nudge in the right direction? </p>