help me to write the python funtion as describe below

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

help me to write the python funtion as describe below

Postby tara » Mon Sep 19, 2016 2:26 am

Assume there are two cars, one following the other, on a one lane road (i.e. no passing). The one in front cannot hold a constant speed, the driver keeps speeding up and slowing down. Specifically, every 20 seconds he hits the accelerator and 20 seconds later the brake.
· Write a Python function which, given a time in seconds, returns whether the brake is being pressed or the accelerator. If the former, return a -1; if the latter, a +1. To check you are doing it right, make a graph of what your function returns for times from 0 to 100 seconds.
Assume that the car in back is trying to keep a constant distance of 50 feet from the car in front. Every time the separation gets greater than 60 feet that driver presses the accelerator and the brake whenever the separation is less than 40.
· Write a Python function which, given a separation in feet also returns a +1 or -1 depending if the accelerator or brake, respectively is being pressed. Check it by making a graph of what your function returns for separations from 20 to 70 feet.
Last edited by micseydel on Mon Sep 19, 2016 4:41 am, edited 1 time in total.
Reason: Initial post lock. Moved to homework section.
tara
 
Posts: 1
Joined: Mon Sep 19, 2016 2:23 am

Re: help me to write the python funtion as describe below

Postby micseydel » Mon Sep 19, 2016 4:41 am

Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: help me to write the python funtion as describe below

Postby Ofnuts » Mon Sep 19, 2016 6:12 am

Every 40 seconds the same thing repeats... what happens depends where you are time modulo 40....
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Homework

Who is online

Users browsing this forum: No registered users and 1 guest

cron