Question

Urgent help needed related python ! Thanx

*On average the population increases by 30% each year due to immigration and natural births. * Every 18 years the population

Write a script called {YourStudentID}_task3.py that calculates the population at the end of a single years cycle. Do not incUsing the techniques demonstrated in the previous tasks, create the full simulation of the town in a script called {YourStude

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution- (Compiled and tested for all test cases)

{YourStudentId}_task3.py

# To read the file
f=open("town_start.txt","r")

# Storing the contents of the file in the variable "contents"
if f.mode == "r":
contents=f.read()
  
# splitting the contents to store food, population, year
contents=contents.split("\n")

food=contents[0]
population=contents[1]
year=contents[2]

# Since population increases by 30% each year
population=int(population)*1.3

#If it is a draft year- population is reduced by 40%
if int(year)%18==0:
population= int(population)*(0.6)
  
#updating the contents with the new values obtained
contents[1]=str(int(population))
contents[2]=str(int(year)+1)
  
# To write into the file
f=open("town_end.txt","w+")
for i in contents:
f.write(i+"\n")

# To close the file
f.close()

Input-

Untitled Telder town startt C Computer Scence question | Che X O localhost8888/edit/Untitled%20Folder/townstart bxt Apps iB P

Output-

C Computer Science question | Che x Untitled Telder town end.txt O localhost8888/edit/Untitled%20Folder/town end.txt Apps iB

{YourStudentID}_task4.py

# To read the file
f=open("town_start.txt","r")

# Storing the contents of the file in the variable "contents"
if f.mode == "r":
contents=f.read()
  
# splitting the contents to store food, population, year
contents=contents.split("\n")

food=int(contents[0])
population=int(contents[1])
year=int(contents[2])

# simulation for 100 years
for i in range(100):
  
# breaking the loop in case if there are no people
if population==0:
break
  
# condition if food is less than the population, some people leave
if food-population < 0:
population = food
food=0
  
# general consumption
else:
food=food-population   
  
  
# Since population increases by 30% each year
population= int(population*1.3)

# If it is a draft year- population is reduced by 40%
if year%18 == 0:
population= int(population*0.6)
  
  
# Since 1/5th food should be thrown away at the end of each year
food = int(food*(4/5))
  
# food to feed for 80% of the population in the next year
food= int(food+ int(0.8*population))

year=year+1
  
  
#updating the contents with the new values obtained
contents[0]=str(food)
contents[1]=str(population)
contents[2]=str(year)
  
# To write into the file
f=open("town_end.txt","w+")
for i in contents:
f.write(i+"\n")

# To close the file
f.close()

Sample Input-

C Computer Science question | Che x Untitled Telder town startt town end.txt + O localhost8888/edit/Untitled%20Folder/townsta

Sample Output-

Untitled Telder town end.txt C Computer Scence question | Che X x town starttx + O localhost8888/edit/Untitled%20Folder/town

Add a comment
Know the answer?
Add Answer to:
Urgent help needed related python ! Thanx *On average the population increases by 30% each year...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Country A 144 Country B 82 43 8 18 10 Population (millions) Crude birth rate (number...

    Country A 144 Country B 82 43 8 18 10 Population (millions) Crude birth rate (number of live births per 1,000 people per year) Crude death rate (number of deaths per 1,000 people per year) Infant mortality rate (number of babies per 1,000 bom who die in first year of life) Total fertility rate (average number of children born to women during their childbearing years) % of population under 15 years old % of population older than 65 years Average...

  • 2.94 points    QUESTION 11 This measure shows how the observed mortality in a population compares...

    2.94 points    QUESTION 11 This measure shows how the observed mortality in a population compares to expectations: age-specific rate cause-specific rate proportional mortality ratio standardized mortality ratio 2.94 points    QUESTION 12 33% of deaths among 44-65 years olds were due to drug overdose is an example of a: age-specific rate cause-specific rate proportional mortality ratio standardized mortality ratio 2.94 points    QUESTION 13 In 2017, there were 300 deaths per 100,000 people aged 25-34 years in Rhode Island....

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

  • please urgent help needed lakt time measure which b. I Discussion Questions ( Why Is It...

    please urgent help needed lakt time measure which b. I Discussion Questions ( Why Is It portant to look a formance, as measured by average Inventory avera e gate flow pe flow time, and average throughput? 3.2 Discuss why it is often easier to measure average inventory and average throughput rather than aver- age flow time How can a manager determine the minimal set of operational measures that should be tracked on a daily basis to predict the financial performances...

  • Question 1 (40 marks) Refer to Table 1. Write the Excel formula for each cell marked...

    Question 1 (40 marks) Refer to Table 1. Write the Excel formula for each cell marked with "" in column C such that formula could be copied and pasted into columns D, and E using Microsoft Excel without further editing, There is no need to explicitly write the Excel formula for cells marked with "Copy & paste". Label each formula clearly with cell reference position. In many country towns of China, there is no western coffee shop such as Starbucks...

  • I just need the excel formula of C27 to C66 Question 1 (40 marks) Refer to...

    I just need the excel formula of C27 to C66 Question 1 (40 marks) Refer to Table 1. Write the Excel formula for each cell marked with “?” in column C such that formula could be copied and pasted into columns D, and E using Microsoft Excel without further editing. There is no need to explicitly write the Excel formula for cells marked with “Copy & paste”. Label each formula clearly with cell reference position. In many country towns of...

  • My topic is diabetes 597690/viewContent/7888874/View The Science of Popular Diets The Impact of Nutrition Practices on...

    My topic is diabetes 597690/viewContent/7888874/View The Science of Popular Diets The Impact of Nutrition Practices on Human Wellness Understanding the Dietary Needs of Special Populations Consider that up until this point in Module 2, we have been focused on the nutritional needs and diet plans for healthy, adult individuals. The AMDRS used to calculate caloric needs have been determined to fit a general population of these individuals. In addition, there has been little need to consider deficiencies or toxicities of...

  • macroeconomic please solve it all i need help 8. If the price of coffee decreases, all...

    macroeconomic please solve it all i need help 8. If the price of coffee decreases, all else held coestant, the Law of Demand states that a firms will produce more coffee b. people will buy more coffee 9. If the price of coffee decreases, all else held constant, the Law of Supply states that a firms will produce more coffee b. people will buy more coffee e. firms will produce less coffee d people will buy more milk shakes c....

  • I have an Assignment of Marketing Research on Climate Change. Where i have to take an...

    I have an Assignment of Marketing Research on Climate Change. Where i have to take an interview of an industry professional, which is done. I have all answer what he said, now i just need to analysis all answer into sub category which are as follow: - 1. Level of Concern of Professionals 2. Impacts on Industry 3. Awareness of Millennials' Knowledge 4. Attitudes Among Millennials If you think any other category could be included please add it. i have...

  • I want to get answers and short explan. 1. 50 year old female states she has...

    I want to get answers and short explan. 1. 50 year old female states she has “the worst headache of her life”. The onset was 20 minutes ago and it was abrupt. Vitals BP 180/90 P56 and R 20. You should suspect? Uncontrolled hypertension migraine headache TIA subarachnoid hemorrhage When lifting a stretcher into the ambulance using power grip, you should? position hands 10’ apart support weight on heels of palms 82 yo F mumbling and throwing clothes, nurse says...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT