1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sidana [21]
3 years ago
9

Create a while loop to try making a video game turn based battle.

Computers and Technology
1 answer:
elena-14-01-66 [18.8K]3 years ago
5 0

import random

monster_health = 20

player_health = 20

while player_health >0 and monster_health>0:

   player_choice = input("Do you wish to attack, heal, or do magic? (type attack, heal, or magic) ")

   if player_choice == "attack":

       damage = random.randint(1,6)

       monster_health -= damage

       print("You attack the monster for",damage,"points of health. The monster has",monster_health,"points of health")

   elif player_choice == "heal":

       heal = random.randint(1,6)

       player_health += heal

       if player_health>20:

           player_health = 20

       print("You heal for",heal,"points of health. Your health is now at",player_health)

   elif player_choice == "magic":

       total = 0

       for x in range(2):

           total += random.randint(1,6)

       monster_health -= total

       print("You attack the monster for",total,"points of health. The monster has",monster_health,"points of health")

   if player_health < 1 or monster_health <1:

       break

   monster_damage = random.randint(1,6)

   player_health -= monster_damage

   print("The monster attacks your for",monster_damage,"points of health. You have",player_health,"points of health remaining.")

if player_health < 1:

   print("You died! Better luck next time!")

elif monster_health < 1:

   print("You defeated the monster! Great job!")

I wrote my code in python 3.8. Best of luck.

You might be interested in
Write a program that defines an interface having the following methods: addition, subtraction, multiplication, and division. Cre
Tatiana [17]

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

1. # -*- coding: utf-8 -*-

2. #Python  

3. class Calculator:

4.     def add(self):

5.         print(a + b)

6.     def sub(self):

7.         print(a - b)

8.     def mul(self):

9.         print(a * b)

10.     def div(self):

11.         print(a / b)

12.  

13. obj = Calculator()

14. choice = 1

15. while choice != 0:

16.     a = int(input("\nEnter first number: "))

17.     b = int(input("Enter first number: "))

18.      

19.     print("\n0. EXIT")

20.     print("1. DIVISION")

21.     print("2. ADDITION")

22.     print("3. SUBTRACTION")

23.     print("4. MULTIPLICATION")

24.      

25.     choice = int(input("\nEnter your choice: "))

26.     if choice == 1:

27.         obj.div()

28.     elif choice == 2:

29.         obj.add()

30.     elif choice == 3:

31.         obj.sub()

32.     elif choice == 4:

33.         obj.mul()

34.     else:

35.         break

Explanation:

  • From lines 1 to 12 we define the object with four methods, addition, subtraction, multiplication, and division. Each method contains the operation between two variables inside a print function
  • On line 13 we instantiate our class
  • On line 14 we declare the variable choice that is going to store the operation that the user wants to perform
  • On line 15 we declare a while loop, this is going to keep running the program until the user wants to exit
  • From line 16 to 18 we ask the user to enter two numbers
  • From line 19 to 24 we print the possible operation, assigning a number for each operation, this indicates to the user what number to press for what operation
  • On line 25 we ask the user for the operation
  • From lines 26 to 35 we check the user input an accordingly we call the corresponding method to performs the operation
7 0
3 years ago
1. Reference initials are always typed on a business letter.
solniwko [45]

Answer:

1. true 2.false 3.a 4.d 5.c 6.d 7. true 8.true 9.true 10.true

Explanation:

5 0
4 years ago
What is the deck of a suspension bridge called​
Allushta [10]

Answer:

that would be the tension in the cables and compression in the towers I believe, my aunt and my uncle work on technology stuff and I'm learning from them.

8 0
3 years ago
A museum is evaluating historical documents for authenticity, reviewing their physical condition, and categorizing them by subje
ZanzabumX [31]

Answer:

Option C

Explanation:

The museum authority can easily automate the process of storage of data on cloud once the document is prepared.

This shall help is easy access to data to all and will also prevent issues arising because of non storage of data or some form of mis-happening leading to data loss.

3 0
3 years ago
A quality assurance test for digital imaging receptors is to check for dark noise. What is the purpose of this test?
baherus [9]

Answer:

The purpose of the quality assurance test is to assess the level of detector noise in the system.

Explanation:

Quality Assurance (QA) is characterized as an operation to ensure a company provides customers with quality products or services. QA concentrates on improving the processes of supplying customers with quality products. A company must ensure the efficiency and effectiveness of the systems in compliance with software products ' quality standards. Quality assurance is commonly referred to as QA monitoring

Purpose of the Quality Assurance:

  • The assurance of quality is to check whether the produced product is appropriate for use. To a certain end, procedures and practices that need to be changed regularly should be pursued by the organization.
  • It mainly focuses on product/service quality that we offer to customers during or after software implementation.
6 0
4 years ago
Other questions:
  • Enter a nested lookup function in cell E4 that uses the cells E2 and E3 to return a specific sales record. For example, using th
    14·1 answer
  • The statement print(words[len(words)]) will raise an exception. What should be placed in the blank so that this exception will b
    11·1 answer
  • Which do switches create?<br> Networks<br> Wireless access points<br> Routes<br> Collision domains
    12·1 answer
  • If you hear that an airplane crashes into the Empire State Building, and you immediately think of the 9/11 terrorist attack on t
    9·1 answer
  • A user has requested a field that counts the number of child records associated with a custom object. These custom objects have
    5·1 answer
  • Websites whose URL’s contain tildes (~) are usually published by the government. True or false?
    8·2 answers
  • Which group on the home ribbon contains commands to control the alignment of text in a document?
    15·1 answer
  • Fill in the blanks of the SQL Statements: Fund_Id VARCHAR(10) , Donor_id VARCHAR(10) , Count_Of_Receipts INTEGER, Total_Receipts
    15·1 answer
  • Qwertyuytrefgvbhnjkmjhgfvbnmjkuhytgfvbnmjkuyhgnjmkiuyhgbnmkloi<br><br> type pig latin now . . .
    14·2 answers
  • onsider a file system on a disk that has both logical and physical block sizes of 512 bytes. assume that the information about e
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!