Need Help ?

Home / Expert Answers / Other / q1-guessing-game-challenge-let-s-use-while-loops-to-create-a-guessing-game-the-challenge-write-a-pro

(Answered): Q1. Guessing Game Challenge Let's use while loops to create a guessing game. The Challenge Write a ...



Q1. Guessing Game Challenge Lets use while loops to create a guessing game. The Challenge Write a program that picks a randoWrite a while loop that compares the players guess to our number. If the player guesses correctly, break from the loop. Othe[4]: # Check ran_check(5,2,7) 5 is in the range between 2 and 7 If you only wanted to return a boolean: [5]: def ran_bool(numOrd string Rogers No. of Upper case characters: 4 No. of Lower case characters: 33 Q5. Write a Python function that takes a l



Q1. Guessing Game Challenge Lets use while loops to create a guessing game. The Challenge Write a program that picks a randoCreate a list to store guesses Hint zero is a good placeholder value. Its useful because it evaluates to False Write a whiQ2. Write a function that computes the volume of a sphere given its radius. The volume of a sphere is given as def vol(rad):? ? assignment (2.pynb ? A lab4pynb a + X OO El lab5. lpynb Code assignment2.ipynb Python 3 . Q4. Write a Python function thaX assignment (2) pyrb ? assignment2.pynb Python 3 4.pynb ? lab5.pynb + XO ? ? » Code (10): unique_list([1,1,1,1, 3,3,3,4,5))
Q1. Guessing Game Challenge Let's use while loops to create a guessing game. The Challenge Write a program that picks a random integer from 1 to 100, and has players guess the number. The rules are: 1. If a player's guess is less than 1 or greater than 100, say "OUT OF BOUNDS" 2. On a player's first turn, if their guess is • within 10 of the number, return "WARM!" • further than 10 away from the number, return "COLD!" 3. On all subsequent turns, if a guess is • closer to the number than the previous guess return "WARMER!" • farther from the number than the previous guess, return "COLDER!" 4. When the player's guess equals the number, tell them they've guessed correctly and how many guesses it took! You can try this from scratch, or follow the steps outlined below. A separate Solution notebook has been provided. Good luck! First, pick a random integer from 1 to 100 using the random module and assign it to a variable Note: random.randint(a,b) returns a random integer in range [a, b], including both end points. : Next, print an introduction to the game and explain the rules Create a list to store guesses Hint: zero is a good placeholder value. It's useful because it evaluates to "False" Write a while loop that asks for a valid guess. Test it a few times to make sure it works. while True : pass Write a while loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses. Some hints Write a while loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses. Some hints: • it may help to sketch out all possible combinations on paper first! • you can use the abs() function to find the positive difference between two numbers if you append all new guesses to the list, then the previous guess is given as guesses[-2] [ ]: while True: # we can copy the code from above to take an input pass That's it! You've just programmed your first game! In the next section we'll learn how to turn some of these repetitive actions into functions that can be called whenever we need them. Functions and Methods Complete the following questions: Q2. Write a function that computes the volume of a sphere given its radius. The volume of a sphere is given as [1]: def vol(rad): pass [2]: # Check vol(2) [2]: 33.49333333333333 Q3. Write a function that checks whether a number is in a given range (inclusive of high and low). [3]: def ran_check(num, low, high): pass [4]: # Check ran_check(5,2,7) 5 is in the range between 2 and 7 If you only wanted to return a boolean: [5]: def ran_bool(num, low, high): pass [6]: ran_bool(3,1,10) [6]: True Q4. Write a Python function that accepts a string and calculates the number of upper case letters and lower case letters. Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?' Expected Output : No. of Upper case characters: 4 No. of Lower case Characters : 33 HINT: Two string methods that might prove useful: .isupper() and.islower) If you feel ambitious explore the Collections module to solve this problem! [7]: def up_low(s): pass [8]: S = 'Hello Mr. Rogers, how are you this fine Tuesday?' up_low(5) Original String : Hello Mr. Rogers, how are you this fine Tuesday? No. of Upper case characters: 4 No. of Lower case Characters : 33 Q5. Write a Python function that takes a list and returns a new list with unique elements of the first list. Sample List : [1,1,1,1,2,2,3,3,3,3,4,5) Unique List : [1, 2, 3, 4, 5] [9]: def unique_list(1st): pass Ord string Rogers No. of Upper case characters: 4 No. of Lower case characters: 33 Q5. Write a Python function that takes a list and returns a new list with unique elements of the first list. Sample List : [1,1,1,1,2,2,3,3,3,3,4,5) Unique List : [1, 2, 3, 4, 5] [9]: def unique_list(1st): pass [10]: unique_list([1,1,1,1,2,2,3,3,3,3,4,5]) [10]: [1, 2, 3, 4, 5] Q6. Write a Python function to multiply all the numbers in a list. Sample List : [1, 2, 3, -4] Expected Output : -24 [11]: def multiply(numbers): pass [12]: multiply([1,2,3,-4]) [12]: -24 Q7. Write a Python function that checks whether a word or phrase is palindrome or not. Note: A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam, kayak racecar, or a phrase "nurses run". Hint: You may want to check out the replace() method in a string to help out with dealing with spaces. Also google search how to reverse a string in Python, there are some clever ways to do it with slicing notation. [13]: def palindrome (s): pass [14]: palindrome ('helleh') [14]: True Q1. Guessing Game Challenge Let's use while loops to create a guessing game. The Challenge Write a program that picks a random integer from 1 to 100, and has players guess the number. The rules are: 1. If a player's guess is less than 1 or greater than 100, say "OUT OF BOUNDS 2. On a player's first turn, if their guess is • within 10 of the number, return "WARM!" • further than 10 away from the number, return "COLDI 3. On all subsequent turns, if a guess is • closer to the number than the previous guess return WARMER!" farther from the number than the previous guess, return "COLDER!" 4. When the player's guess equals the number, tell them they've guessed correctly and how many guesses it took! You can try this from scratch, or follow the steps outlined below. A separate Solution notebook has been provided. Good luck! . First, pick a random integer from 1 to 100 using the random module and assign it to a variable Note: random.randint(a,b) returns a random integer in range [a, b], including both end points. ... Next, print an introduction to the game and explain the rules ... Create a list to store guesses Hint: zero is a good placeholder value. It's useful because it evaluates to "False" Create a list to store guesses Hint zero is a good placeholder value. It's useful because it evaluates to "False" Write a while loop that asks for a valid guess. Test it a few times to make sure it works. while True: pass Write a while loop that compares the player's guess to our number. If the player guesses correctly, break from the loop. Otherwise, tell the player if they're warmer or colder, and continue asking for guesses. ho Some hints: • it may help to sketch out all possible combinations on paper first! • you can use the abs() function to find the positive difference between two numbers . if you append all new guesses to the list, then the previous guess is given as guesses[-2] 1 ]: While True: # we can copy the code from above to take an input pass ... That's it! You've just programmed your first game! In the next section we'll learn how to turn some of these repetitive actions into functions that can be called whenever we need them. Functions and Methods Complete the following questions: Q2. Write a function that computes the volume of a sphere given its radius. de command In 1 Col 1 ass med Q2. Write a function that computes the volume of a sphere given its radius. The volume of a sphere is given as def vol(rad): pass # Check vol(2) : 33.49333333333333 Q3. Write a function that checks whether a number is in a given range (inclusive of high and low). I def ran_check(num, low, high): pass ... # Check ran_check(5,2,7) 5 is in the range between 2 and 7 If you only wanted to return a boolean: 51: def ran_bool(nun, low, high): pass ... 5]: ran_bool(3,1,10) 5]: True Q4. Write a Python function that accepts a string and calculates the number of upper case letters and lower case letters. Sample String : Hello Mr. Rogers, how are you this fine Tuesday?' Expected Output : No. of Upper case characters : 4 No. of Lower case Characters : 33 Mode: Command Ln 1 Col 1 assignment2.pnb ? ? assignment (2.pynb ? A lab4pynb a + X OO El lab5. lpynb Code assignment2.ipynb Python 3 . Q4. Write a Python function that accepts a string and calculates the number of upper case letters and lower case letters. Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?' Expected Output : No. of


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to Q1. Guessing Game Challenge Let's use while loops to create a guessing game. The Challenge Write a program that picks a ...
We have an Answer from Expert

Buy This Answer $4

Place Order