In this level you need to search through a string looking for certain key words.
Underneath the starter code below, create a for loop that will iterate through every word in the key_word list. Make sure you give your iterator variable a good name, as you will need it to refer to each keyword as you iterate through the list.
Inside the for loop create an if statement with a condition that checks to see if the current keyword is in the string paragraph.
If the word is in paragraph, print a message to the console that the word has been found.
Otherwise, print that the word was not found.
Note12.7.2.
If you arenβt sure how to check whether a string is in another string, look at Section 6.4 in the textbook.
Output should look like this:
Subsection12.7.2Level 2
In this level, you need to sort grades into categories of A, B, C, D and F. The grades need to be separated as follows: A >= 90, 90 > B >= 75, 75 > C >= 60, 60 > D >= 50, 50 > F
Create a for loop that will iterate 50 times.
In the for loop, create a variable that will be set to a random value from 0 to 100.
Inside the for loop write code that will appropriately determine the letter grade that goes with the random numeric grade. You will want to use a chained conditional (if-elif-elif) type of structure to check for the different grade levels. For each level, print out the numeric and associated letter grade.
The end result should look something like this (this is shortened example):
Note12.7.3.
Reference the textbook Section 6.9 on chained conditionals if you donβt remember the syntax.
Subsection12.7.3Level 3
In this level you will create a game of chance, similar to the card game war. Two players will have a random number generated from 1 to 52 (inclusive), the player with the higher number will win the point. In the case of a tie, a point is awarded to both players. 26 rounds will be played, after which the winner will be displayed.
Start off by creating two variables to hold points, one for player 1 and one for player 2. Initialize these variables to 0.
Create a for loop that will iterate for 26 rounds - note that we have created a constant for this, which you should use.
Inside this loop, create two more variables (one for player 1βs card and one for player 2βs card) and assign them random values ranging from 1 to 52 (inclusive), using the randrange function. This represents the 52 cards in a standard deck of cards.
Add a print statement that spritns out both players cards (see the samepl output below).
Still inside the loop, create a chained conditional statement that responds to three possible states for this card round: if player 1βs card was higher, if player 2βs card was higher, or if it was a tie. Inside each branch of this chained conditional there should be a print statement printing out who got the point (see sample screenshot at the bottom of the level). Inside each branch, you also need to assign points to the winner of each round by incrementing player1βs points, or player2βs points. In the case of a tie, they should both get a point.
After the for loop, we want to check to see who won the game. Similar to step 4, we need a chained conditional statement to check if player 1 has the most points, or if player 2 has the most points, or if it is a tie. Inside each branch of this chained conditional there should be a print statement printing out the winner and their final score (see sample photo at the bottom of the level)
An output example can be seen below (this is a shortened example)
Bonus: Organizing output is just as important as organizing code! Add round numbers before each round, a blank line after each round and indent the print statements for each round. (See sample output below)
Note12.7.4.
Some useful characters for this bonus are: \n and \t, which are escape sequences that give you a newline or a tab.