write the most functional version of this program. You will compare the age of a given...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write the most functional version of this program. You will compare the age of a given character with the nine companions of the Fellowship of the Ring. Write a program that compares the age of any character of your choice with the nine companions on quest to destroy the One Ring: the hobbit and ring bearer Frodo Baggins and his gardener Sam Gamgee, the wizard Gandalf, the elf Legolas, the dwarf Gimli, the men Aragorn the ranger and Boromir of Gondor, and the two young hobbits Merry Brandybuck and Pippin Took 1. Ask the user for a name and age of a character. 2. Print out a message displaying the character's age and listing the characters who are older than the given character (print nothing if there are none) 3. Print out a message displaying the character's age and listing the characters who are younger than the given character (print nothing if there are none) Here is the data that you will need: 1. Frodo (51 years old) 2. Samwise (39 years old) 3. Gandalf (2000 years old) 4. Legolas (2931 years old) 5. Gimli (140 years old) 6. Aragorn (88 years old) 7. Boromir (41 years old) 8. Merry (37 years old) 9. Pippin (29 years old) The data structures that you must use for this version are two parallel lists. You should hardcode them as follows: names = ] ages ● [ "Frodo", ● "Samwise", "Gandalf", "Legolas", "Gimli", "Aragorn", "Boromir", "Merry", "Pippin", = [51, 39, 2000, 2931, 140, 88, 41, 37, 29] For this version, if the entered age is negative, the program should print "Invalid age." and exit the program. For this version, you can assume that the user will never enter the age of a character that is the same as the age of any of the characters given in the names list.i.e your program does not need to consider the case if age of character entered by user is equal to any of the numbers in the ages list. For this version, you cannot use the dictionaries data structure. For this version, think of a way to generalize your solution. We have nine companions in the Fellowship of the Ring but your code must support any number of companions (5, 10, 100, 10000). This means you can not use hard coded variables and multi-level nested if statements anymore. Hints 1. Think about how a for loop can help you in this version of the program. 2. The name of a character and their corresponding age will always be at the same position in their respective list objects i.e. if Frodo is at position 0 in the names list, then their age 51 will also be at position 0 in the ages list. Think about how you can use the range function and the subscription operation to access the name of the character and their corresponding age. 3. Consider using two list objects (names_older and names_younger) to store the names of characters that are older and younger than the character entered by the user. write the most functional version of this program. You will compare the age of a given character with the nine companions of the Fellowship of the Ring. Write a program that compares the age of any character of your choice with the nine companions on quest to destroy the One Ring: the hobbit and ring bearer Frodo Baggins and his gardener Sam Gamgee, the wizard Gandalf, the elf Legolas, the dwarf Gimli, the men Aragorn the ranger and Boromir of Gondor, and the two young hobbits Merry Brandybuck and Pippin Took 1. Ask the user for a name and age of a character. 2. Print out a message displaying the character's age and listing the characters who are older than the given character (print nothing if there are none) 3. Print out a message displaying the character's age and listing the characters who are younger than the given character (print nothing if there are none) Here is the data that you will need: 1. Frodo (51 years old) 2. Samwise (39 years old) 3. Gandalf (2000 years old) 4. Legolas (2931 years old) 5. Gimli (140 years old) 6. Aragorn (88 years old) 7. Boromir (41 years old) 8. Merry (37 years old) 9. Pippin (29 years old) The data structures that you must use for this version are two parallel lists. You should hardcode them as follows: names = ] ages ● [ "Frodo", ● "Samwise", "Gandalf", "Legolas", "Gimli", "Aragorn", "Boromir", "Merry", "Pippin", = [51, 39, 2000, 2931, 140, 88, 41, 37, 29] For this version, if the entered age is negative, the program should print "Invalid age." and exit the program. For this version, you can assume that the user will never enter the age of a character that is the same as the age of any of the characters given in the names list.i.e your program does not need to consider the case if age of character entered by user is equal to any of the numbers in the ages list. For this version, you cannot use the dictionaries data structure. For this version, think of a way to generalize your solution. We have nine companions in the Fellowship of the Ring but your code must support any number of companions (5, 10, 100, 10000). This means you can not use hard coded variables and multi-level nested if statements anymore. Hints 1. Think about how a for loop can help you in this version of the program. 2. The name of a character and their corresponding age will always be at the same position in their respective list objects i.e. if Frodo is at position 0 in the names list, then their age 51 will also be at position 0 in the ages list. Think about how you can use the range function and the subscription operation to access the name of the character and their corresponding age. 3. Consider using two list objects (names_older and names_younger) to store the names of characters that are older and younger than the character entered by the user.
Expert Answer:
Answer rating: 100% (QA)
Python code for given question def compareagecharactername characterage names ages namesolder namesyounger for i in rangelennames if agesi characterag... View the full answer
Related Book For
Project Management A Systems Approach To Planning Scheduling And Controlling
ISBN: 9781119805373
13th Edition
Authors: Harold Kerzner
Posted Date:
Students also viewed these programming questions
-
Discuss carefully how alternative investments compare to traditional investments, what the differences are and what the advantages of alternative investments are over traditional investments.
-
Determine the marginal rate of substitution between cost and warranty of product in the Table below. Comment on you result Alternatives iPhone 8 6 Samsung 5 4 Attributes Cost(AED K) Warranty (yrs)...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Pick a company or brand or business on which to focus. What business is it inP Who are its direct and indirect competitors? Which in each category are the most relevant competitors?
-
Find the transfer function Vo(s)/Vi(s) for the network shown in fig. Briefly.
-
KOM pays the following insurance premiums during 2016: Auto accident and liability insurance: Paid 1/1/16 Coverage period 1/1/16 - 12/31/16 ............... $3,500 Fire, storm, and other casualty...
-
At a given radial location, a 15-mph wind against a windmill results in the upstream (1) and downstream (2) velocity triangles shown in Fig. P12.4. Sketch an appropriate blade section at that radial...
-
For its fabricated metal products, the Able Corp. is buying $10,000 of special tools that have a 4-year useful life and no salvage value . Compute the depreciation charge for the second year by each...
-
Summarize the information fromthe 3 years' financial statements, theratio calculations, and industry comparisons provided in the case topresent possible solutions to the company's profitability...
-
Build this interface with Java and give me the code Model Welcome to Model ads Welcome User Login Form UserName Password Passowd Get Username get Password 2022 Model
-
X Corp has $100 of accumulated E&P and ($50) of current E&P, without taking into account the distribution in question here. It makes a cash distribution on the 90th day of the non-leap year...
-
a. Distinguish between profit optimisation under monopoly and under perfect competition. 4 Marks b. A competitive firm has the following demand function Q-2000 +20P with the following cost function...
-
(a) Explain the meaning of labour economics (2 marks). (b) With the help of diagrams explain how the important aspects of labour economics are fitted in micro-economics and macro-economic concepts...
-
QUESTION FIVE (a) Using IS-LM framework, discuss how the government can use both fiscal and monetary policies to influence the performance of the economy. (10marks) (b) Briefly explain the remedial...
-
1. Calculate Tour de Force (TdF) plc's annual growth rate for sales, assets, and operating profit in 2019 and 2020. Explain fully what are the underlying drivers of these growth rates?
-
QUESTION TWO By citing relevant examples describe seven (7) limitations of Ricardian comparative cost theory of international trade (15 marks). QUESTION THREE Briefly explain the variables in the...
-
53.A metal plate 5 cm by 5 cm rests on a layer of castor oil 1 mm thick whose coefficient of viscosity is 1.55 Nsm Calculate the magnitude of applied force with a speed of 2cm/s. EN
-
Provide examples of a situations in which environmental disruptions affected consumer attitudes and buying behaviors.
-
In which type of matrix structure would a project manager most likely have a command of technology? A. Strong matrix B. Balanced matrix C. Weak matrix D. Cross-cultural matrix
-
In which organizational form is it most difficult to integrate project activities? A. Classical/traditional B. Projectized C. Strong matrix D. Weak matrix
-
If the start date of a project is delayed but the budget and specifications remain fixed, what would the project manager most likely trade off first? A. Scope B. Time C. Quality D. Risk
-
The U-tube in Fig. P2.160 rotates at \(2.0 \mathrm{rev} / \mathrm{sec}\). Find the absolute pressures at points \(C\) and \(B\) if the atmospheric pressure is 14.696 psia. Recall that \(70{ }^{\circ}...
-
A valve has a failure rate of 0.06 failures per year. A periodic inspection performed once a year can detect 60% of the failures. The valve is operated for 10 years before it is removed from service...
-
An instrument has a failure rate of 0.015 failures per year. All failures are immediately detectable. The MTTR is 24 hours. What is steady state unavailability?
Study smarter with the SolutionInn App