python code informactice 3 question

 1.Write an algorithm for resolving a battle among the classic Pokemon types.

       The user should select a type of either fire, water or grass. The computer should randomly select one of those three types as well.

Don't use plagiarized sources. Get Your Custom Essay on
python code informactice 3 question
Just from $13/Page
Order Essay

      To determine if the user or computer wins, or if it is a draw: fire is stronger than grass, grass is stronger than water, and water is stronger than fire. Whomever chose the stronger type is the winner. If both chose the same type it is a draw.

       See

here

for an example of what an algorithm should look like. Your algorithm should be at a similar level of detail.

       See

here (Links to an external site.)

(

http://cgi.soic.indiana.edu/~dpierz/pokemon.html

) for an example of the interactions and determining a winner (the example has pictures, your algorithm needs only to consider text based inputs and messages)

       If you submit python code instead on an algorithm you will not receive points for this question.

2.Write a program that ask the user for a string as input. It should duplicate of all the characters in the string and print it back out to the user. For example: AbC123 would be printed out as AAbbCC112233

3.Write a program that takes two lists and displays the items that occur in both lists. For example: [“a”, “b”, “c”] [“c”, “a”, “d”] would display a and c

Algorithm Example

For the following task:

Use the random module to write a number guessing game.

The number the computer chooses should change each time you run the program.

Repeatedly ask the user for a number. If the number is different from the computer’s let the user know if they guessed too high or too low. If the number matches the computer’s, the user wins.

Keep track of the number of tries it takes the user to guess it.

An appropriate algorithm might be:

Import the random module

Display a welcome message to the user

Choose a random number between 1 and 100

Get a guess from the user

Set a number of tries to 0

As long as their guess isn’t the number

Check if guess is lower than computer

If so, print a lower message.

Otherwise, is it higher?

If so, print a higher message.

Get another guess

Increment the tries

Repeat

When they guess the computer’s number, display the number and their tries count

Notice that each line in the algorithm corresponds to roughly a line of code in Python, but there is no coding itself in the algorithm. Rather the algorithm lays out what needs to happen step by step to achieve the program.

Calculator

Calculate the price of your paper

Total price:$26
Our features

We've got everything to become your favourite writing service

Need a better grade?
We've got you covered.

Order your paper