Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python and please use two function Pikachu is surrounded by pesky Gengars! Will Pikachu be able to defeat all the ghosts, or will their

image text in transcribedimage text in transcribedin python and please use two function

Pikachu is surrounded by pesky Gengars! Will Pikachu be able to defeat all the ghosts, or will their numbers prove too great for our hero? You must write a program to answer this question. When your program starts, allow the user to input the number of Gengars that are attacking Pikachu (you may assume the user enters a positive number). Then, you must simulate a series of battles between Pikachu and a Gengar. Initially, Pikachu has 35 health, but he may lose health during the battles, and if he ever runs out of health, he faints! The Gengars will attack one at a time, and the rules for the battle simulation are as follows. Note that you will definitely need to import Python's random module, as there is luck in the simulation. The Gengar attacks first. It has a 50% chance to hit Pikachu (Hint: Use the random () function to gen- erate a random float between 0 and 1, then check if that float is less than 0.5). If the Gengar hits, it will randomly deal either 1, 2, or 3 damage to Pikachu. Then Pikachu attacks. Pikachu has a 60% chance to hit the Gengar. If he does, he will defeat the ghost. The ghosts will attack in turn until either they are all defeated, or Pikachu faints. When that happens, print out a message that describes the outcome. If Pikachu defeated all the Gengars, print out that he triumped and how much health he has left If Pikachu fainted, print out how many of the Gengars he managed to defeat. Sample Run Sample input and output for Pikachu winning (input typed by the user is shown in green text): 15 How many Gengars are attacking Pikachu? Pikachu defeated all 15 Gengars ! He has 20 health left! And another sample where Pikachu faints How many Gengars are attacking Pikachu? 30 After bravely defeating 23 Gengars, Pikachu fainted. First, write a function to simulate a single battle between Pikachu and one Gengar. Pikachu's current health should be a parameter to this function, and the function should return the amount of health Pikachu has remaining after the battle is over. Make sure this function is working before going on! Put print() statements into your function to print out intermediate values during the battle to see if they make sense. You'll take these print() statements out later (the sample output above doesn't have them), but they're invaluable for testing your function. Page 6 CMPT 141/113 UNIVERSITY OF SASKATCHEWAN Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, SN 5C9, Canada Telephine: (306) 966-4886, Facimile: (306) 966-4884 Winter 2021 Introduction to Computer Science Step 2 Second, in the "main" part of your Python program, use console input to ask the user for the number of Gengars. You can assume the user will enter a positive integer. Then, use a loop to keep calling your function from Step 1 so long as there are still Gengars to defeat and Pikachu hasn't fainted. Once the loop is done, display the outcome to the console as per the sample output shown above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago