Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Utilizing arithmetic operators and arrays: To this point in your programming you may assume that arithmetic operators are solely used for mathematical operations however there

  1. Utilizing arithmetic operators and arrays: To this point in your programming you may assume that arithmetic operators are solely used for mathematical operations however there are cool things you can do with them outside of basic math. An example of this is the modulus (%). Modulus can be used to access indices outside of the length of your array.

Consider the following array:

summonTypes = ["soldier", "archer", "peasant", "paladin"]

Although the array only has 4 elements, with the use of % you can summon more than 4 troops.

The following code provides an example of how this would work. But there is a catch! There is an error in the code below. Use your debugging skills to identify the error, correct it and get the proper output.

summonTypes = ["soldier", "archer", "peasant", "paladin"]

for i in range(10):

type = summonTypes[ i % summonTypes.length ]

hero.summon(type)

Correct code in python please

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

Explain the importance of HRM to all employees.

Answered: 1 week ago

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago