menu
bartleby
search
close search
Hit Return to see all results

in Python, Write a program for a (very) rudimentary shooter "game". You are the only shooter and you start with ammo of 10. The one enemy doesn't shoot back and starts with health of 5. Code a custom function named shoot that prints "Shot fired" and returns True for a hit or False for a miss. Generate a random 0 to assign False or 1 to assign True. In the main function, use a while loop that runs the shoot function until you run out of ammo, at which point you lose. Report both hits and misses (see Sample Outputs). If your shot is a hit as determined by the value returned by shoot, your code should lower the enemy's health. If you are lucky, the health of the enemy will be reduced to zero before you run out of ammo. If this happens, report the enemy's demise and use the break keyword to stop the loop. You have won.Sample Output 1Shot fired. Enemy was hit!Shot fired. Shot missedShot fired. Enemy was hit!Shot fired. Enemy was hit!Shot fired. Enemy was hit!Shot fired. Enemy was hit!Enemy destroyed. You won!GAME OVERSample Output 2Shot fired. Shot missedShot fired. Enemy was hit!Shot fired. Shot missedShot fired. Shot missedShot fired. Shot missedShot fired. Enemy was hit!Shot fired. Shot missedShot fired. Shot missedShot fired. Shot missedShot fired. Enemy was hit!You are out of ammo! You lose!GAME OVER

Question

in Python, 

Write a program for a (very) rudimentary shooter "game". You are the only shooter and you start with ammo of 10. The one enemy doesn't shoot back and starts with health of 5. Code a custom function named shoot that prints "Shot fired" and returns True for a hit or False for a miss. Generate a random 0 to assign False or 1 to assign True. In the main function, use a while loop that runs the shoot function until you run out of ammo, at which point you lose. Report both hits and misses (see Sample Outputs). If your shot is a hit as determined by the value returned by shoot, your code should lower the enemy's health. If you are lucky, the health of the enemy will be reduced to zero before you run out of ammo. If this happens, report the enemy's demise and use the break keyword to stop the loop. You have won.
Sample Output 1
Shot fired. Enemy was hit!
Shot fired. Shot missed
Shot fired. Enemy was hit!
Shot fired. Enemy was hit!
Shot fired. Enemy was hit!
Shot fired. Enemy was hit!
Enemy destroyed. You won!
GAME OVER

Sample Output 2
Shot fired. Shot missed
Shot fired. Enemy was hit!
Shot fired. Shot missed
Shot fired. Shot missed
Shot fired. Shot missed
Shot fired. Enemy was hit!
Shot fired. Shot missed
Shot fired. Shot missed
Shot fired. Shot missed
Shot fired. Enemy was hit!
You are out of ammo! You lose!
GAME OVER

check_circleAnswer
Step 1
  • Import random module and use random.randint() method, which only returns integer type values in between given range.
  • In main method assign a count variable with starting value 5 and a am...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: How would I open a file and encrypt that file from a dictionary in Python? Attached is a picture of ...

A: The functions are implemented in python 3. Since the python dictionary given in convert function is ...

question_answer

Q: In C++ Create a 3X3 array with random integers.  Create a function that adds together all the value ...

A: To write a program in C++, that consist of an array of 3 by 3 elements, a function that adds the val...

question_answer

Q: Assume the following declarations and initializations (MIN, MAX, num) are made just before each sub-...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

question_answer

Q: Is BIOS volatile?

A: Volatile memory is the computer memory that maintains its data only when the computer is in power. A...

question_answer

Q: Consider a program that allows a surgeon in one city to assist in an operation on a patient in anoth...

A: The following can attack the program:A career criminalA cracker mightThe harm they can cause is foll...

question_answer

Q: Based on the code that I already have, please help me complete it. I am attempting to use 2 function...

A: Corrections in Program:Add a closing bracket after return statement of main.Remove the parameters fr...

question_answer

Q: Develop the ‘Shape’ application such that: Implement an array of objects of various types (all SIX ...

A: Program plan: Define a class called “Shape”.Define a default constructor to print the message.Define...

question_answer

Q: Draw an EER diagram for the following situation using the traditional EER notation. A technology com...

A: EER diagram is stand for enhanced entity relationship diagram. EER is used for designed high- level ...

question_answer

Q: In Python 3.7.4 Write a program that will compute the total cost of an amazon purchase. The program ...

A: ProgramSince two questions have been given and it is not clear the answer is sought for which questi...

Sorry about that. What wasn’t helpful?