SlideShare a Scribd company logo
1 of 15
CSCI 1100 — Computer Science 1 Homework 4
Loops and Lists
Overview
This homework is worth 90 points total toward your overall
homework grade (each part is 30
points), and is due Thursday, March 2, 2017 at 11:59:59 pm.
There are three parts to the homework,
each to be submitted separately. All parts should be submitted
by the deadline or your program
will be considered late.
The homework submission server URL is below for your
convenience:
https://submitty.cs.rpi.edu/index.php?semester=s17&course=csc
i1100
Your programs for each part for this homework should be
named:
hw4Part1.py
hw4Part2.py
hw4Part3.py
respectively. Each should be submitted separately.
See the handout for Homework 3 for discussion of grading and
for a discussion of what is considered
excess collaboration. These rules will be in force for the rest of
the semester.
Final note, you will need to use loops in this assignment. We
will leave the choice of loop type
to you. Please feel free to use while loops or for loops
depending on the task and your personal
preference.
Part 1: Words with alternating vowels and consonants
Write a program that reads in words entered by the user and
checks whether:
• the word has at least 8 characters,
• starts with a consonant,
• has alternating consonants and vowels, and
• the consonants are in decreasing alphabetical order.
The program should loop reading additional words until the user
enters an empty string.
Note that you can check letters for alphabetical order using <.
For example:
>>> 'a' > 'b'
False
>>> 'z' > 'b'
True
https://submitty.cs.rpi.edu/index.php?semester=s17&course=csc
i1100
Your program should work for words entered upper or lower
case, and must use a function is_alternating(word)
that returns True if the word has the above pattern, and False
otherwise. You are welcome to
use additional functions if you would like. Hint. Remember to
write a loop that goes through
each letter and check for the necessary conditions. Using
indexing is important here as you need
to compare letters in different positions. Here is an example run
of this program:
Enter a word: zayexiwo
The word 'zayexiwo' is alternating
Enter a word: zaYexiWov
The word 'zaYexiWov' is alternating
Enter a word: zaaexiWov
The word 'zaaexiWov' is not alternating
Enter a word: zYYexiWov
The word 'zYYexiWov' is not alternating
Enter a word: zayexiwx
The word 'zayexiwx' is not alternating
Enter a word: zayexiw
The word 'zayexiw' is not alternating
Enter a word: azayexiw
The word 'azayexiw' is not alternating
Enter a word: zazexiwo
The word 'zazexiwo' is not alternating
Enter a word:
And using real words,
Enter a word: remolade
The word 'remolade' is alternating
Enter a word: zucchini
The word 'zucchini' is not alternating
Enter a word: serenade
The word 'serenade' is alternating
Enter a word: topologic
The word 'topologic' is alternating
Enter a word: zodiacal
The word 'zodiacal' is not alternating
Enter a word:
Here is a little hint that will help: Given a letter stored in the
variable x, the boolean expression:
x in 'aeiou'
is True if and only if x is a lower case vowel.
When you have tested your code, please submit it as
hw4Part1.py. Be sure you use the correct
filename, otherwise, Submitty will not be able to grade your
submission.
Part 2: New York State Death Statistics
As part of an open government initiative, New York State
releases a large number of health related
statistics for researchers and developers to use. Among these
are death statistics by region of the
state at https://health.data.ny.gov. For this assignment, we have
simplified the statistics to
provide just the total number of deaths per 100,000 people. Our
goal is to come up with a simple
visualization comparing death trends between two different
counties over the last few years.
Write a program to read in the death statistics for two different
areas of NYS for the 11 years from
2003 to 2013. Remember that these are deaths per 100,000
people. We will take the naive view
that areas with decreasing trends per 100,000 are automatically
healthier places to live, ignoring
all other population demographics such as age. For the two
areas chosen, compute a trend for the
death rates composed of the symbols =, +, and -, where =
implies the year is within +/- 5 deaths
per 100,000 of the previous year, + implies the year has more
than 5 more deaths than the previous
year, and and - implies that the year has more than 5 fewer
deaths than the previous year. Starting
from 2004, compute the trend for that year as compared to 2003
and encode it in the trend. Then
move on to 2005, 2006 and etc. until you reach 2013. Your
trend will run from 2004 through 2013.
Print the trend lines for the two areas in reverse order from
2013 - 2004 and then compare the
number of + and - symbols for each area. Basically, every + will
add one to the trend value and
every - will subtract one. Report which area has the better trend
(lowest score) or report that the
two areas have the same trend.
The utility module provided for this homework will give you
some help. Given a string containing
a county name, it provides a function read_deaths(county) that
returns you a list of 11 numbers.
Try the following:
https://health.data.ny.gov
import hw4_util
cdata1 = hw4_util.read_deaths('Erie')
cdata2 = hw4_util.read_deaths('Cattaraugus')
print('Erie:', cdata1)
print('Cattaraugus:', cdata2)
would give:
Erie: [1061.0, 1032.0, 1047.0, 1020.0, 1040.0, 1037.0, 1029.4,
1010.0, 1043.0, 1014.0,
1046.0]
Cattaraugus: [1005.0, 1089.0, 1061.0, 978.7, 972.7, 978.8,
1010.2, 1083.0, 1002.0,
977.9, 990.0]
The difference (rounded to one decimal) is:
Erie: [-29.0, 15.0, -27.0, 20.0, -3.0, -7.6, -19.4, 33.0, -29.0,
32.0]
Cattaraugus: [84.0, -28.0, -82.3, -6.0, 6.1, 31.4, 72.8, -81.0, -
24.1, 12.1]
Running the program with these values would give:
Enter the first area to check => Erie
Erie
Enter the second area to check => Cattaraugus
Cattaraugus
Erie:
2013 2004
Trend: +-+--=+-+-
Cattaraugus:
2013 2004
Trend: +--+++---+
Erie has better trend statistics than Cattaraugus.
Note that 2013 and 2004 are printed to line up with the margins
of the trend data.
Here is another example where the number of ”+” and ”-”
symbols are the same:
Enter the first area to check => Erie
Erie
Enter the second area to check => Erie
Erie
Erie:
2013 2004
Trend: +-+--=+-+-
Erie:
2013 2004
Trend: +-+--=+-+-
Erie and Erie are the same.
The function hw4_util.read_deaths will return an empty list
whenever the county cannot be
found. Your program must give an error and exit when it
encounters an invalid name as shown
below.
Enter the first area to check => Errie
Errie
Errie is an invalid name
or
Enter the first area to check => Erie
Erie
Enter the second area to check => Wesstchaester
Wesstchaester
Wesstchaester is an invalid name
You can ignore any warnings you get from using sys.exit() that
may show up after your error
message.
When you have tested your code, please submit it as
hw4Part2.py. Be sure to use the correct
filename or Submitty will not be able to grade your submission.
Part 3: Pokemon GO
This is a little variation on the pikachu walk we did last
homework. This time, we place a Pokemon
trainer at (0, 0) on an infinite grid. As in the previous
homework N moves up in the negative y
direction, S moves down in the positive y direction, E moves
right in the positive x direction and W
moves left in the negative x direction. We will discard NE, NW,
SE, and SW directions. The grid
is populated by roaming Pokemon and your job is to wait while
they walk around and hopefully
run into you.
You will need to read the list of Pokemon and their initial
locations on the grid using the read_pokemon
function from hw4_util. By now you should be experts at this.
For example, the program:
import hw4_util
pokemon, locations = hw4_util.read_pokemon()
print(pokemon)
print(locations)
Will produce:
['Pikachu', 'Bulbasaur', 'Charizard', 'Squirtle']
[(-3, -2), (-1, -4), (1, 0), (2, 4)]
The first list is the pokemon that are available on this particular
grid, while the second list is
their initial locations. You may assume without checking that
no pokemon are repeated in this
list. The pokemon trainer sits and waits for pokemon to walk
around the grid one step at a time.
Each pokemon can move in one of 4 directions N (up), S
(down), E (right) and W (left). When
the pokemon lands on the same space as the trainer, (0, 0), the
pokemon is considered captured.
We won’t require you to animate the pokemon battles for this
homework. The simulation has an
indeterminate number of steps driven by user input.
The Program
This is a turn based simulation driven by user input. To set up
the simulation, first use read_pokemon
to load in the pokemon data. Immediately print out the list of
Pokemon and their locations using a
function print_pokemon that you will need to write. The
function should only print out pokemon
that have not been captured by the trainer. This will allow you
to use it at additional places in
the simulation.
Once you have the simulation set up you enter a loop. At the
start of each iteration through the
loop begin by asking the user for a command:
1. N moves up one step
2. S moves down one step
3. E moves right one step
4. W moves left one step
5. print print all active (uncaptured) pokemon and their
locations
6. end stop the simulation and end the program
If the command is one of the directions, immediately ask which
pokemon moved and move them
appropriately, printing out their new location at the end of the
move and noting if they were
captured. the command print prints out the information on each
uncaptured pokemon. The
simulation ends when the end command is entered. A sample
run is below:
Current pokemon:
Pikachu at (-3, -2)
Bulbasaur at (-1, -4)
Charizard at (1, 0)
Squirtle at (2, 4)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> W
W
Which pokemon moved W? Charizard
Charizard
Charizard moved to location (0, 0)
You capture a Charizard on turn 1
N,S,E,W to move, 'print' to list, or 'end' to stop ==> print
print
Current pokemon:
Pikachu at (-3, -2)
Bulbasaur at (-1, -4)
Squirtle at (2, 4)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> end
end
Simulation ended.
Or a second example:
Current pokemon:
Pikachu at (-3, -2)
Bulbasaur at (-1, -4)
Charizard at (1, 0)
Squirtle at (2, 4)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> prrint
prrint
N,S,E,W to move, 'print' to list, or 'end' to stop ==> W
W
Which pokemon moved W? Charizard
Charizard
Charizard moved to location (0, 0)
You capture a Charizard on turn 2
N,S,E,W to move, 'print' to list, or 'end' to stop ==> S
S
Which pokemon moved S? Pikachu
Pikachu
Pikachu moved to location (-3, -1)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> print
print
Current pokemon:
Pikachu at (-3, -1)
Bulbasaur at (-1, -4)
Squirtle at (2, 4)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> N
N
Which pokemon moved N? Squirtle
Squirtle
Squirtle moved to location (2, 3)
N,S,E,W to move, 'print' to list, or 'end' to stop ==> end
end
Simulation ended.
A longer example can be found in hw4_pokemon_example.txt in
hw4Files.zip.
Some notes:
1. You can assume an infinite field and do not need to check
boundaries.
2. Make sure that your commands are case insensitive
3. You can expect that the pokemon names will be entered
correctly, including capitalization,
but you are welcome to check it if you want.
4. If you get an invalid command (such as prrrint in the second
example) just ignore it and start
the next turn
When you have tested your code, please submit it as
hw4Part3.py. You must use this filename, or
Submitty will not be able to run and grade your code.

More Related Content

Similar to CSCI 1100 — Computer Science 1 Homework 4Loops and Lists.docx

CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxCS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxmydrynan
 
Notes2
Notes2Notes2
Notes2hccit
 
Types For Frontend Developers
Types For Frontend DevelopersTypes For Frontend Developers
Types For Frontend DevelopersJesse Williamson
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsRuth Marvin
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
Impossible Programs
Impossible ProgramsImpossible Programs
Impossible ProgramsC4Media
 
Scratch for kids syllabus for 5 hours by bibek pandit
Scratch for kids syllabus for 5 hours by bibek panditScratch for kids syllabus for 5 hours by bibek pandit
Scratch for kids syllabus for 5 hours by bibek panditBibekPandit2
 
Maze solving app listing
Maze solving app listingMaze solving app listing
Maze solving app listingChris Worledge
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetHoang Nguyen Phong
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part維佋 唐
 
1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdfJavier Crisostomo
 

Similar to CSCI 1100 — Computer Science 1 Homework 4Loops and Lists.docx (18)

ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docxCS10 Python Programming Homework 4 40 points Lists, Tupl.docx
CS10 Python Programming Homework 4 40 points Lists, Tupl.docx
 
Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
 
Notes2
Notes2Notes2
Notes2
 
Types For Frontend Developers
Types For Frontend DevelopersTypes For Frontend Developers
Types For Frontend Developers
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
Impossible Programs
Impossible ProgramsImpossible Programs
Impossible Programs
 
While loop
While loopWhile loop
While loop
 
Java Practice Set
Java Practice SetJava Practice Set
Java Practice Set
 
Scratch for kids syllabus for 5 hours by bibek pandit
Scratch for kids syllabus for 5 hours by bibek panditScratch for kids syllabus for 5 hours by bibek pandit
Scratch for kids syllabus for 5 hours by bibek pandit
 
Exponents
ExponentsExponents
Exponents
 
Maze solving app listing
Maze solving app listingMaze solving app listing
Maze solving app listing
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
 
Looping
LoopingLooping
Looping
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part
 
L06
L06L06
L06
 
1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf1_1_python-course-notes-sections-1-7.pdf
1_1_python-course-notes-sections-1-7.pdf
 

More from annettsparrow

Initial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxInitial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxannettsparrow
 
initial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxinitial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxannettsparrow
 
Initial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxInitial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxannettsparrow
 
Initial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxInitial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxannettsparrow
 
Initial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxInitial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxannettsparrow
 
Initial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxInitial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxannettsparrow
 
Initial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxInitial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxannettsparrow
 
Initial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxInitial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxannettsparrow
 
Initial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxInitial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxannettsparrow
 
Initial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxInitial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxannettsparrow
 
Initial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxInitial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxannettsparrow
 
Infrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxInfrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxannettsparrow
 
Inital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxInital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxannettsparrow
 
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxInfornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxannettsparrow
 
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docxINFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docxannettsparrow
 
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxINFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxannettsparrow
 
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
Informative Presentation Delivery OutlineI.  HeaderSpeec.docxInformative Presentation Delivery OutlineI.  HeaderSpeec.docx
Informative Presentation Delivery OutlineI. HeaderSpeec.docxannettsparrow
 
Informed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxInformed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxannettsparrow
 
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxINFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxannettsparrow
 
Information Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxInformation Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxannettsparrow
 

More from annettsparrow (20)

Initial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docxInitial Post  (250 words)Read and interpret the short story .docx
Initial Post  (250 words)Read and interpret the short story .docx
 
initial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docxinitial post one paragraph intext citation and reference Require.docx
initial post one paragraph intext citation and reference Require.docx
 
Initial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docxInitial Post InstructionsTriggers are ethnocentric responses to .docx
Initial Post InstructionsTriggers are ethnocentric responses to .docx
 
Initial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docxInitial Post InstructionsFor the initial post,consider thr.docx
Initial Post InstructionsFor the initial post,consider thr.docx
 
Initial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docxInitial Post InstructionsFor the initial post, choose and ad.docx
Initial Post InstructionsFor the initial post, choose and ad.docx
 
Initial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docxInitial Post InstructionsDiscuss the differences and similaritie.docx
Initial Post InstructionsDiscuss the differences and similaritie.docx
 
Initial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docxInitial Post InstructionsAs we jump into the world of Alge.docx
Initial Post InstructionsAs we jump into the world of Alge.docx
 
Initial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docxInitial Post InstructionsFor the initial post, respond to one .docx
Initial Post InstructionsFor the initial post, respond to one .docx
 
Initial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docxInitial Post InstructionsAgenda setting can be a difficult t.docx
Initial Post InstructionsAgenda setting can be a difficult t.docx
 
Initial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docxInitial Post Identify all the components of a cell. Describe the fu.docx
Initial Post Identify all the components of a cell. Describe the fu.docx
 
Initial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docxInitial Discussion Board Post Compare and contrast life for col.docx
Initial Discussion Board Post Compare and contrast life for col.docx
 
Infrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docxInfrastructure SecurityChapter 10Principles of Compute.docx
Infrastructure SecurityChapter 10Principles of Compute.docx
 
Inital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docxInital post please respond for the above post question one page with.docx
Inital post please respond for the above post question one page with.docx
 
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docxInfornnation Technologyin Hunnan ResourceAnEmpirical .docx
Infornnation Technologyin Hunnan ResourceAnEmpirical .docx
 
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docxINFORMED CONSENT LETTER  Page 1 of 2 SELF CONSENT .docx
INFORMED CONSENT LETTER Page 1 of 2 SELF CONSENT .docx
 
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docxINFORMATIONGOVERNANCEFounded in 1807, John W.docx
INFORMATIONGOVERNANCEFounded in 1807, John W.docx
 
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
Informative Presentation Delivery OutlineI.  HeaderSpeec.docxInformative Presentation Delivery OutlineI.  HeaderSpeec.docx
Informative Presentation Delivery OutlineI. HeaderSpeec.docx
 
Informed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docxInformed Consent FormBy the due date assigned, submit the Inform.docx
Informed Consent FormBy the due date assigned, submit the Inform.docx
 
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docxINFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
INFORMATION THAT SHOULD GO INTO PROCESS RECORDING FOR MICRO WORK.docx
 
Information Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docxInformation Technology Capstone ProjectIn this course, learners .docx
Information Technology Capstone ProjectIn this course, learners .docx
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Recently uploaded (20)

LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 

CSCI 1100 — Computer Science 1 Homework 4Loops and Lists.docx

  • 1. CSCI 1100 — Computer Science 1 Homework 4 Loops and Lists Overview This homework is worth 90 points total toward your overall homework grade (each part is 30 points), and is due Thursday, March 2, 2017 at 11:59:59 pm. There are three parts to the homework, each to be submitted separately. All parts should be submitted by the deadline or your program will be considered late. The homework submission server URL is below for your convenience: https://submitty.cs.rpi.edu/index.php?semester=s17&course=csc i1100 Your programs for each part for this homework should be named: hw4Part1.py hw4Part2.py hw4Part3.py respectively. Each should be submitted separately. See the handout for Homework 3 for discussion of grading and for a discussion of what is considered
  • 2. excess collaboration. These rules will be in force for the rest of the semester. Final note, you will need to use loops in this assignment. We will leave the choice of loop type to you. Please feel free to use while loops or for loops depending on the task and your personal preference. Part 1: Words with alternating vowels and consonants Write a program that reads in words entered by the user and checks whether: • the word has at least 8 characters, • starts with a consonant, • has alternating consonants and vowels, and • the consonants are in decreasing alphabetical order. The program should loop reading additional words until the user enters an empty string. Note that you can check letters for alphabetical order using <. For example: >>> 'a' > 'b' False >>> 'z' > 'b' True https://submitty.cs.rpi.edu/index.php?semester=s17&course=csc
  • 3. i1100 Your program should work for words entered upper or lower case, and must use a function is_alternating(word) that returns True if the word has the above pattern, and False otherwise. You are welcome to use additional functions if you would like. Hint. Remember to write a loop that goes through each letter and check for the necessary conditions. Using indexing is important here as you need to compare letters in different positions. Here is an example run of this program: Enter a word: zayexiwo The word 'zayexiwo' is alternating Enter a word: zaYexiWov The word 'zaYexiWov' is alternating Enter a word: zaaexiWov The word 'zaaexiWov' is not alternating Enter a word: zYYexiWov The word 'zYYexiWov' is not alternating Enter a word: zayexiwx The word 'zayexiwx' is not alternating Enter a word: zayexiw
  • 4. The word 'zayexiw' is not alternating Enter a word: azayexiw The word 'azayexiw' is not alternating Enter a word: zazexiwo The word 'zazexiwo' is not alternating Enter a word: And using real words, Enter a word: remolade The word 'remolade' is alternating Enter a word: zucchini The word 'zucchini' is not alternating Enter a word: serenade The word 'serenade' is alternating Enter a word: topologic The word 'topologic' is alternating Enter a word: zodiacal The word 'zodiacal' is not alternating
  • 5. Enter a word: Here is a little hint that will help: Given a letter stored in the variable x, the boolean expression: x in 'aeiou' is True if and only if x is a lower case vowel. When you have tested your code, please submit it as hw4Part1.py. Be sure you use the correct filename, otherwise, Submitty will not be able to grade your submission. Part 2: New York State Death Statistics As part of an open government initiative, New York State releases a large number of health related statistics for researchers and developers to use. Among these are death statistics by region of the state at https://health.data.ny.gov. For this assignment, we have simplified the statistics to provide just the total number of deaths per 100,000 people. Our goal is to come up with a simple visualization comparing death trends between two different counties over the last few years. Write a program to read in the death statistics for two different areas of NYS for the 11 years from 2003 to 2013. Remember that these are deaths per 100,000 people. We will take the naive view that areas with decreasing trends per 100,000 are automatically healthier places to live, ignoring all other population demographics such as age. For the two areas chosen, compute a trend for the death rates composed of the symbols =, +, and -, where =
  • 6. implies the year is within +/- 5 deaths per 100,000 of the previous year, + implies the year has more than 5 more deaths than the previous year, and and - implies that the year has more than 5 fewer deaths than the previous year. Starting from 2004, compute the trend for that year as compared to 2003 and encode it in the trend. Then move on to 2005, 2006 and etc. until you reach 2013. Your trend will run from 2004 through 2013. Print the trend lines for the two areas in reverse order from 2013 - 2004 and then compare the number of + and - symbols for each area. Basically, every + will add one to the trend value and every - will subtract one. Report which area has the better trend (lowest score) or report that the two areas have the same trend. The utility module provided for this homework will give you some help. Given a string containing a county name, it provides a function read_deaths(county) that returns you a list of 11 numbers. Try the following: https://health.data.ny.gov import hw4_util cdata1 = hw4_util.read_deaths('Erie') cdata2 = hw4_util.read_deaths('Cattaraugus') print('Erie:', cdata1) print('Cattaraugus:', cdata2) would give: Erie: [1061.0, 1032.0, 1047.0, 1020.0, 1040.0, 1037.0, 1029.4,
  • 7. 1010.0, 1043.0, 1014.0, 1046.0] Cattaraugus: [1005.0, 1089.0, 1061.0, 978.7, 972.7, 978.8, 1010.2, 1083.0, 1002.0, 977.9, 990.0] The difference (rounded to one decimal) is: Erie: [-29.0, 15.0, -27.0, 20.0, -3.0, -7.6, -19.4, 33.0, -29.0, 32.0] Cattaraugus: [84.0, -28.0, -82.3, -6.0, 6.1, 31.4, 72.8, -81.0, - 24.1, 12.1] Running the program with these values would give: Enter the first area to check => Erie Erie Enter the second area to check => Cattaraugus Cattaraugus Erie: 2013 2004 Trend: +-+--=+-+- Cattaraugus: 2013 2004
  • 8. Trend: +--+++---+ Erie has better trend statistics than Cattaraugus. Note that 2013 and 2004 are printed to line up with the margins of the trend data. Here is another example where the number of ”+” and ”-” symbols are the same: Enter the first area to check => Erie Erie Enter the second area to check => Erie Erie Erie: 2013 2004 Trend: +-+--=+-+- Erie: 2013 2004 Trend: +-+--=+-+- Erie and Erie are the same. The function hw4_util.read_deaths will return an empty list
  • 9. whenever the county cannot be found. Your program must give an error and exit when it encounters an invalid name as shown below. Enter the first area to check => Errie Errie Errie is an invalid name or Enter the first area to check => Erie Erie Enter the second area to check => Wesstchaester Wesstchaester Wesstchaester is an invalid name You can ignore any warnings you get from using sys.exit() that may show up after your error message. When you have tested your code, please submit it as hw4Part2.py. Be sure to use the correct filename or Submitty will not be able to grade your submission. Part 3: Pokemon GO This is a little variation on the pikachu walk we did last homework. This time, we place a Pokemon trainer at (0, 0) on an infinite grid. As in the previous
  • 10. homework N moves up in the negative y direction, S moves down in the positive y direction, E moves right in the positive x direction and W moves left in the negative x direction. We will discard NE, NW, SE, and SW directions. The grid is populated by roaming Pokemon and your job is to wait while they walk around and hopefully run into you. You will need to read the list of Pokemon and their initial locations on the grid using the read_pokemon function from hw4_util. By now you should be experts at this. For example, the program: import hw4_util pokemon, locations = hw4_util.read_pokemon() print(pokemon) print(locations) Will produce: ['Pikachu', 'Bulbasaur', 'Charizard', 'Squirtle'] [(-3, -2), (-1, -4), (1, 0), (2, 4)] The first list is the pokemon that are available on this particular grid, while the second list is their initial locations. You may assume without checking that no pokemon are repeated in this list. The pokemon trainer sits and waits for pokemon to walk around the grid one step at a time. Each pokemon can move in one of 4 directions N (up), S (down), E (right) and W (left). When the pokemon lands on the same space as the trainer, (0, 0), the
  • 11. pokemon is considered captured. We won’t require you to animate the pokemon battles for this homework. The simulation has an indeterminate number of steps driven by user input. The Program This is a turn based simulation driven by user input. To set up the simulation, first use read_pokemon to load in the pokemon data. Immediately print out the list of Pokemon and their locations using a function print_pokemon that you will need to write. The function should only print out pokemon that have not been captured by the trainer. This will allow you to use it at additional places in the simulation. Once you have the simulation set up you enter a loop. At the start of each iteration through the loop begin by asking the user for a command: 1. N moves up one step 2. S moves down one step 3. E moves right one step 4. W moves left one step 5. print print all active (uncaptured) pokemon and their locations 6. end stop the simulation and end the program
  • 12. If the command is one of the directions, immediately ask which pokemon moved and move them appropriately, printing out their new location at the end of the move and noting if they were captured. the command print prints out the information on each uncaptured pokemon. The simulation ends when the end command is entered. A sample run is below: Current pokemon: Pikachu at (-3, -2) Bulbasaur at (-1, -4) Charizard at (1, 0) Squirtle at (2, 4) N,S,E,W to move, 'print' to list, or 'end' to stop ==> W W Which pokemon moved W? Charizard Charizard Charizard moved to location (0, 0) You capture a Charizard on turn 1 N,S,E,W to move, 'print' to list, or 'end' to stop ==> print print Current pokemon: Pikachu at (-3, -2)
  • 13. Bulbasaur at (-1, -4) Squirtle at (2, 4) N,S,E,W to move, 'print' to list, or 'end' to stop ==> end end Simulation ended. Or a second example: Current pokemon: Pikachu at (-3, -2) Bulbasaur at (-1, -4) Charizard at (1, 0) Squirtle at (2, 4) N,S,E,W to move, 'print' to list, or 'end' to stop ==> prrint prrint N,S,E,W to move, 'print' to list, or 'end' to stop ==> W W Which pokemon moved W? Charizard Charizard Charizard moved to location (0, 0)
  • 14. You capture a Charizard on turn 2 N,S,E,W to move, 'print' to list, or 'end' to stop ==> S S Which pokemon moved S? Pikachu Pikachu Pikachu moved to location (-3, -1) N,S,E,W to move, 'print' to list, or 'end' to stop ==> print print Current pokemon: Pikachu at (-3, -1) Bulbasaur at (-1, -4) Squirtle at (2, 4) N,S,E,W to move, 'print' to list, or 'end' to stop ==> N N Which pokemon moved N? Squirtle Squirtle Squirtle moved to location (2, 3) N,S,E,W to move, 'print' to list, or 'end' to stop ==> end end Simulation ended.
  • 15. A longer example can be found in hw4_pokemon_example.txt in hw4Files.zip. Some notes: 1. You can assume an infinite field and do not need to check boundaries. 2. Make sure that your commands are case insensitive 3. You can expect that the pokemon names will be entered correctly, including capitalization, but you are welcome to check it if you want. 4. If you get an invalid command (such as prrrint in the second example) just ignore it and start the next turn When you have tested your code, please submit it as hw4Part3.py. You must use this filename, or Submitty will not be able to run and grade your code.