Note that there are some explanatory texts on larger screens.

plurals
  1. POLooking for Guidance to Continue My First Program
    text
    copied!<p>I'm looking to do the following in this program:</p> <p>I want to ask the user to set a range of hours they want to sleep in (from when they go to sleep until they wake up). Then, award points proportional to the amount of hours they slept within that range.</p> <p>Keep in mind that I started learning Python yesterday and had zero experience with any programming language before that.</p> <p>Here is what I've got so far:</p> <pre><code># Timeslot(TS) of hours slept. TS_start_sleep = int(raw_input("What time did you go to sleep last night:")) TS_end_sleep = int(raw_input("What time did you wake up this morning:")) def sleep_TS(points): if </code></pre> <p>Also, here is the first part of my program (in cases it helps show my level of knowledge). This section works just fine (I debugged everything) but please feel free to suggest ways that would make it better / more efficient.</p> <pre><code>points = 0 # Beginning points. # SLEEP # Amount of hours slept. hrs_slept = int(raw_input("Hours slept today:")) def sleep_length(points): if hrs_slept == 8: points += 50 elif 9 &lt;= hrs_slept &lt;= 17: points = -10 * hrs_slept + 120 elif 4 &lt;= hrs_slept &lt;= 7: points = 10 * hrs_slept - 40 elif 0 &lt;= hrs_slept &lt;= 3: points = 10 * hrs_slept - 50 else: print "Invalid input. Valid hours are between 0 and 17." points_sleep_length = points print "+", points, "points" sleep_length(points) </code></pre> <p>Thank you for reading!</p> <p>Edit: Also, I've been using Codeacademy to learn python up until now. However, I'd also be interested in hearing what else the community recommends for learning python and other programming languages as I am going through the material pretty quickly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload