def sumDigits(n)
sumDigits(234)
returns 9
(2+3+4).
Write a main method that prompts the user to enter an integer and displays
the sum of all its digits.
ch06_pr02.py
.python3 ch06_pr02.py
on MAC and
py -3 ch06_pr02.py
on Windows)
user provides input:
Enter a number: 234
The digits of 234 sum to 9
def displaySortedNumbers(num1, num2, num3)
ch06_pr05.py
.python3 ch06_pr05.py
on MAC and
py -3 ch06_pr05.py
on Windows)
user provides input:
Enter three numbers: 3, 2.4, 5
The sorted numbers are 2.4 3 5
python3 ch06_pr05.py
on MAC and
py -3 ch06_pr05.py
on Windows)
user provides input:
Enter three numbers: 31, 12.4, 15
The sorted numbers are 12.4 15 31
def convertMillis(millis)
hours:minutes:seconds
. For
example
convertMillis(5500)
returns a string 0:0:5
,
convertMillis(100000)
returns a string 0:1:40
, and
convertMillis(555550000)
returns a string 154:19:10
.
Your main method should take an amount of milliseconds from a user and
display a string in the format hours:minutes:seconds
.
ch06_pr23.py
.python3 ch06_pr23.py
on MAC and
py -3 ch06_pr23.py
on Windows)
user provides input:
Enter a time in milliseconds: 5500
Time in hours:minutes:seconds is 0:0:5
python3 ch06_pr23.py
on MAC and
py -3 ch06_pr23.py
on Windows)
user provides input:
Enter a time in milliseconds: 100000
Time in hours:minutes:seconds is 0:1:40
python3 ch06_pr23.py
on MAC and
py -3 ch06_pr23.py
on Windows)
user provides input:
Enter a time in milliseconds: 555550000
Time in hours:minutes:seconds is 154:19:10
findClosestAngle
and
sensePlanAct
. findClosestAngle
will use the servo
to scan angles from 10 to 170 at an increment of 5 degrees and the function
will return the angle at which the closest obstacle was present. Use
time.sleep(0.05)
to allow the servo to move 5 degrees and
time.sleep(1)
to allow the servo to rotate back to degree 10.
The function sensePlanAct
will find the closest angle (by
invoking the other function), turn to face the closest obstacle, and then
drive forward 10cm. Further, the method will do this 5 times and stop the
robot. main
will invoke sensePlanAct
.
find_closest_obstacle.py
.cat find_closest_obstacle.py | ssh pi@gopigoXX python3 -u
on MAC and
type find_closest_obstacle.py | ssh pi@gopigoXX python3 -u
on Windows,
remember to use the correct hostname)
user provides input (output may vary):
find_closest_obstacle.txt
. In this file,
please answer the following questions:
time.time()
returns the elapsed time in seconds since midnight of January 1, 1970.
Write a program that displays the date and time. You must account
for leap years. Months should be displayed as three letter abbreviations.
The time should not account for time zones, i.e., the time displayed will be
in UTC+0 or GMT. Hint: use functions liberally.
ch06_pr31.py
.python3 ch06_pr31.py
on MAC and
py -3 ch06_pr31.py
on Windows)
user provides input:
Current date and time is Jan 29, 2017 16:41:5