Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
COSC-111 Spring 2014
Project-1
February 13, 2014
Your assignment is to write a Python program that helps the user calculate how manydays he or she will need to recover from jetlag. Your program is due Mon, Feb-24, at11:59 pm. To turn it in, use the Submit server at app.cs.amherst.edu/Submit andsubmit two files:
1. Your file of Python code. Name it buley.py.
2. A trace file showing how your code works on a particular set of inputs. See the endof this handout for more information.
Buley’s Formula The International Civil Aviation Organization (ICAO) uses Buley’sformula to calculate how many days of rest a person (such as a pilot) needs to recover fromjet lag. The formula takes four inputs:
• T is the number of hours in transit
• z is the number of time zones crossed.
• dep is the local departure time.
• arr is the local arrival time.
Departure and Arrival times are used in this formula according to the 24-hour militaryclock. So 1200 is noon, 1430 is 2:30 pm, and so forth.
The times are used to find the departure coefficient d and the arrival coefficient aaccording to this table:
Time of day d = dept-coeff a = arr-coef
0800-1159 0 41200-1759 1 21800-2159 3 02200-0059 4 10100-0759 3 3
1
Where 0=good, 1,2 = fair, 3 = poor, and 4 = bad. If z ≥ 4 the formula is
days =T2 + (z − 4) + d + a
10
If z < 4 then the (z − 4) part should be set to zero in this formula.For full credit your program should:
1. Prompt the user for the necessary information.
2. Check for bad inputs and refused to do a wrong calculation if found (more about thisbelow).
This includes checking for invalid time, and checking that T and/or z are in reason-able ranges. if a bad input is detected, the program should print an error messageexplaining what the problem is, and invite the user to try again.
Your program does not have to check that the user typed in numbers (as opposedto strings) – in that case just let it crash. Your program does not have to checkfor sensible combinations of values (perhaps the pilot is flying around in circles ortraveling at the speed of light), just for invalid ranges of individual values. But youare welcome to add these checks if you can figure out how to do it.
3. Calculate how many days of rest are need to recover, according to the above formula.
4. Tell the user how many days of rest are needed. The program should round thisnumber up to the nearest half-day.
Example: The user leaves Montreal at 1800 hours local time (d = 3), spends ninehours travelling, and arrives in Paris at 0800 hours (a = 4), having crossed 5time zones.The number of days of rest needed is 1.25. Rounding up to the nearest half-day, theprogram prints the answer as 1.5 days.
Checking your work. A chart of world time zones is attached for your amusement.Here are some example inputs and the answers. Use these to check your work.
• The user travels 5 hours through 5 time zones, departing at 5 minutes after midnightand arriving 5 minutes after midnight. The answer should be 0.85, rounded up to 1day.
• The user travels 12 hours through 6 time zones, departing at 10pm and arriving at4am. The answer should be 1.5, rounded up to 1.5 days.
• The user travels 3 hours through 2 time zones, departing at 10 am and arriving at8pm. The answer is 0.15, rounded up to 0.5 days.
2
• The user travels 1 hour through 0 time zones (i.e. staying in the same time zone),departing at 11:30 pm and arriving at 12:30 am. The answer is 0.55 days, roundedup to 1 day.
What to turn in. As usual point your browser to www.cs.amherst.edu/Submit, findthe Program 1 submit page, and turn in the following two files.
1. The program buley.py, of course.
2. A file named proj1script.txt that is a transcript record of you (as user) interactingwith your program. You can make this script by running your program the usualway inside the IDLE shell (the interactive part), and then selecting File:Save As. . .in the menu bar.
(a) Your transcript should show your program running with the inputs from the“Checking your work” section above.
(b) Then, as user, you should type in some errors to show off how your programcopes with bad inputs. Use as many bad inputs as you need to demonstrateyour work.
Note: Do not try to edit the proj1script.txt file, for example to clean up typos anderrors that you might have created as user. You will not be penalized for being a clumsyuser. But, if you edit the file you may create mis-matches between what the script saysyour program does and what your program actually does. A professor who notices sucha mismatch will wonder if you’re trying to fake the output to get a better grade. You ofcourse do not want to alarm the professor and waste his or her time in that way.
3
105
30
75
0
30
0
30
150120
151515
60
45
45
15
45
135135 45
60
60
30
606060
120150 30
3030
75
75
45
105165
75
0 18090
45
90
1515
15 15
15
165
MACE.
TURKMENISTAN
POLAND
(AUSTL.)
LESOTHO
I N D I A
AFGHANISTAN
SWEDEN
(AUSTL.)
GHANA
U N I T E D S T A T E S
NEPAL
IRELAND
(AUSTL.)
C A N A D A
I N D O N E S I A
BOLIVIA
British IndianOcean Territory
BENIN
Svalbard
BURMA
(INDIA)
CENTRALAFRICAN REPUBLIC
LAOS
(U.K.)
GABON
DOM.REP.
(EQ. GUI.)
ANGOLA
HAITI
(SPAIN)
ZAMBIA
(U.S.)
JAMAICA
(PORT.)
TOGO
(France)
EL SALVADOR
Greenland
GUINEA-BISSAU
(U.K.)
PANAMA
KOS.
CHILE(AUSTL.)
BELIZE
KUWAIT
U.S.
MAURITANIA
MAURITIUS
HONDURAS
MALAWI
VANUATU
TANZANIA
(DENMARK)
VENEZUELA
(ECUADOR)
Am.Sam.
R U S S I A
BAHRAIN U.S.
(NORWAY)
SURINAME
(MAURITIUS)
TONGA
UNITED
SOUTHKOREA
(JA
PAN)
(FRANCE)
(FRANCE)
PORTUGAL
Taiwan
(IT.)
(FRANCE)
(Fr. S. and Ant. Lands)
PAPUANEW GUINEA
TURKEY
PHILIPPINES
(PORT.)
(CHILE)
PARAGUAY
(N.Z.)
MARSHALL
ISLANDS
UKRAINE
MONGOLIA
(BRAZIL)
UGANDA
MinamitoriShima
TIMOR-LESTE
AZER.
SRILANKA
Hong KongS.A.R.
(BRAZIL)
ZIMBABWE
Guam
K I R I B A T I
IRAQ
(COSTA RICA)
MOZAMBIQUE
(U.S.)
U.S.
SYRIA
LIBERIA
REP. OFTHE
CONGO
(CHILE)
YEMEN
(administered by U.K.claimed by ARGENTINA)
KINGDOM
BOS.&
(CHILE)
ERITREA
Bermuda
NETH.
AUS.
WakeIsland(U.S.)
(FRANCE)
ETHIOPIA
(FR.)
GREECE
HUNG.
Tokelau
BakerIsland
ALGERIA
(FRANCE)
HER.
CZ. REP.
K I R I B A T I
HowlandIsland
CHAD
NewCaledonia
ISRAEL
RUS.
(Mexico)
(N.Z.)
SUDAN
St. Pierreand Miquelon
OMAN
LAT.
(Fr. S. and Ant. Lands)
(AUSTL.)
CAPE VERDE
(N.Z.)
TAJIKISTAN
BEL.
(Fr. S. and Ant. Lands)
(SOUTH AFRICA)
NIGER
MacauS.A.R.
UZBEKISTAN
GERMANY
SER.
French Southern and Antarctic Lands
BURUNDI
A U S T R A L I A
PAKISTAN
FINLAND
Ashmore andCartier Islands
SWAZILAND
C H I N AI R A N
NORWAY
ChristmasIsland
CÔTED'IVOIRE
B R A Z I L
BHUTAN
MOROCCO
Cocos(Keeling)Islands
U.S.
VIETNAM
COLOMBIAMALDIVES
EQUATORIAL GUINEA
(YEMEN)
M A L A Y S I A
(INDIA)
ANG.
THAILAND
SEYCHELLES
NAMIBIA
South Georgia andSouth Sandwich Islands(administered by U.K.
claimed by ARGENTINA)
WesternSahara
SOUTHAFRICA
Falkland Islands(Islas Malvinas)
THEBAHAMAS
EGYPT
JarvisIsland
NICARAGUA
(NORWAY)
GUINEAClipperton IslandCOSTARICA
(DENMARK)
Pitcairn Islands
GUATEMALA
MONT.
ARGENTINA
SENEGAL
COMOROS
CUBA
QATAR
BRUNEI
KENYA
MALTA
ECUADOR
BURKINAFASO
SAMOA
MALI
occupied by the SOVIET UNION in 1945, administered by RUSSIA, claimed by JAPAN
FaroeIslands
PERU
Tromelin Island
TUVALU
ICELAND
UNITEDARAB
EMIRATES
NORTHWESTERNHAWAIIANISLANDS
Jan Mayen
Agalega Islands
NAURU
SPAINNORTHKOREA
(FR.)
TRINIDAD ANDTOBAGO
GUYANA
Reunion
NEWZEALAND
ITALY
CAMBODIA
(IT.)
FrenchGuiana
(N.Z.)
SOLOMONISLANDS
BELARUS
JAPAN
Saint Helena,Ascension,
andTristan da Cunha
(U.K.)
(BRAZIL)
URUGUAY
CookIslands
FEDERATED STATES OF MICRONESIA
ROMANIA
BANGLADESH
KAZAKHSTAN
(BRAZIL)
BOTSWANA
(JAPAN)
PALAU
GEO.
SIERRALEONE
DEM. REP.OF THECONGO
(COL.)
MADAGASCAR
(U.S.)
MEXICO
LEB.
(CHILE)
CAMEROON
NorthernMarianaIslands
DENMARK
CYPRUS
SAUDIARABIA
(CHILE)
SAO TOMEAND PRINCIPE
(U.K.)
LUX.
SWITZ.
JohnstonAtoll(U.S.)
F r e n c h P o l y n e s i a
DJIBOUTI
Coral SeaIslands
MOLDOVA
SLOV.
MidwayIslands
(U.S.)
(U.S.)
SOMALIA
Wal.& Fut.
ALB.
SLO.
(N.Z.)
(U.S.)
LIBYA
FIJI
CRO.
BULGARIA
(INDIA)
(U.S.)
SOUTHSUDAN
(AUSTL.)
JORDAN
LITH.
(French Polynesia)
(AUSTL.)
NIGERIA
SINGAPORE
ARM.
EST.
(Fr. S. and Ant. Lands)
(NORWAY)
THEGAMBIA
TUNISIA
KYRGYZSTAN
FRANCE
(Fr. S. and Ant. Lands)
(FRANCE)
RWANDA
1:0011:00
Saint Helena
NICOBAR
Annobon
Isla San Felix
Sun13:00
Corsica
ISLANDS
Niue
Isla Sala y Gómez
24:007:00
Sardinia
(number indicates standard timein zone when it is 12 noon, UTC) Heard Island and
McDonald Islands
Easter Island
Sun6:00
Sicily
NorfolkIsland
Lord HoweIsland
21:004:00
MADEIRAISLANDS
GALAPAGOSISLANDS
Gough Island
23:00
STANDARD TIME ZONES OF THE WORLD, AUGUST 2013
CANARYISLANDS
Sakhalin
WrangelIsland
14:00
Tasmania
subtract 24 hours
NEWSIBERIAN ISLANDS
12:00
ÎLES KERGUELEN
add 24 hours
SEVERNAYAZEMLYA
1:00
GILBERTISLANDS
TRISTAN DA CUNHA
KERMADECISLANDS
Boundary representation is not necessarily authoritative.
NOVAYAZEMLYA
16:00
Ascension
EAST
FRANZ JOSEFLAND
10:00
Add time zone number to UTC to obtain local time.
Scale 1:85,000,000 at 0º
WEST
22:00
Subtract time zone number from local time to obtain UTC.
Miller Cylindrical Projection
Sun
Island ofNewfoundland
8:00 00:00
HAWAIIANISLANDS
Socotra
ARCHIPIÉLAGOJUAN
FERNÁNDEZ
3:00
formerly Greenwich Mean Time (GMT)
LI N
E I S
LA
ND
S
ISLASREVILLAGIGEDO
Bouvet Island
15:00
Coordinated Universal Time (UTC)CHATHAMISLANDS
ÎLES MARQUISES
PRINCE EDWARDISLANDS
5:00
803569AI (G01802) 9-13Subtract time zone number from UTC to obtain local time.
Martin Vaz
ISLANDS
2:00
R Y U K Y U I
SL
AN
DS
Sun
Add time zone number to local time to obtain UTC.
Trinidade
ANDAMAN
19:00
A L E U T I A N I S L A N D S
PHOENIX ISLANDS
Île Saint-Paul
ARQUIPÉLAGO DEFERNANDO
DE NORONHA
LAKSHADWEEP
20:00
Île Amsterdam
PENEDOS DE SÃO PEDRO
E SÃO PAULO
18:00
ÎLES CROZET
Isla deMalpelo
AZORES
17:00
Westward across Date Line
Isla del Coco
Sun9:00
K U R I L IS L A
ND
S
Eastward across Date Line
Isla San Ambrosio
Sea ofJapan
Bering SeaLabrador
Sea
N O RTH
PA C IF I C
O C E A N
Kara Sea
AralSea
LakeBaikal
Barents Sea
SouthChina Sea
East Siberian Sea
I N D I A N
O C E A N
Baffin Bay
CaspianSea
PhilippineSea
Black Sea
Bay ofBengal
Greenland Sea
DavisStrait
S O UTH PA C IF I C
O C E A N
Sea
ArabianSea
Mediterranean Sea
N O RTH
ATL A NTI C
O C E A N
CoralSea
A R C T I C O C E A N
C ar ibb ean S ea
DenmarkStrait
Red
Great AustralianBight
MozambiqueChannel
Sea ofOkhotsk
Beaufort Sea
ChukchiSea
Gulf of Mexico
A R C T I C O C E A N
NorthSea
PersianGulf
TasmanSea
Gulf of Guinea
Laptev Sea
S O UTH
ATL A NTI C
O C E A N
ChukchiSea
LakeBalkhash
HudsonBay
NorwegianSea
N O RTH
PA C IF I C
O C E A N
+8
+3
+6
-4
-3
+5
+3
+5
-5
-4
+5¾
+5
+4
+4
-4
-5
+6½
+6
+3
+3
-4
-6
+5½
+8
0
+2
-3
-7
+5½
+9
+1
+1
0
-8
+9
+12
+1
-1
0
-9
+4½
+11
+2
0
-1
-10
+13
+5½
+10
+2
-2
-1
-11
+14
+5½
+9
+3
-3
-5
-11
-10
+13
+8
+5
-5
-6
-12
+13
+6
+7
+12
-8
-7
-3
+5
+6
+10
-4
-8
-11
+5
+11
-6
-9
-10
-10
-11
+12¾
-7
-3½
-12
-11
-11
-12
+11½
-9
+3
-11
+12
+10½
-10
+4
-10
+11
+6½
-11
+2
-9½
+9
-9
+10
+9½
+1
+10
+11
+9
-3
0
+4
+11
+8
-3
-3
-1
+3½
+7
+12
+7
-4½
-2
Inte
rnat
ion
al D
ate
Lin
e
Inte
rnat
ion
al D
ate
Lin
e
International Date Line
Sydney
Bangkok
Lagos
Kisangani
Perth
Taipei
Casablanca
Bogotá
AliceSprings
Khartoum
MexicoCity
Urumqi
Buenos Aires
Barcelona
Nairobi
Shanghai
Algiers
Seoul
Astana
Guangzhou
Kabul
Johannesburg
Tokyo
Beijing
Riyadh
Rome
Santiago
Yekaterinburg
Baghdad
Winnipeg
Yakutsk
Tehran
Vancouver
Vladivostok
Medan
Toronto
Samara
Makassar
Repulse Bay
SaintPetersburg
Jakarta
Québec
Caracas
Petropavlovsk-Kamchatskiy
NewDelhi
Iqaluit
Washington, D.C.
Novosibirsk
Mumbai
Edmonton
New York
Moscow
Kolkata
Dawson
Los Angeles
Magadan
Qaanaaq(Thule)
Ho ChiMinh City
Denver
Krasnoyarsk
Nuuk(Godthåb)
Rangoon
Dallas
Izhevsk
Ittoqqorttoormiit(Scoresbysund)
SãoPaulo
Chicago
Irkutsk
Paris
Manaus
Anchorage
Manila
AddisAbaba
Brasília
London
Lima
Cairo
Dhaka
Istanbul
Karachi
Kinshasa
0 500 1000 Kilometers
0 500 1000 Miles