Question

In: Computer Science

Please make a Python program where the computer chooses a number and the player guesses the...

Please make a Python program where the computer chooses a number and the player guesses the number.

You need an input, a random number, if statement, and a while loop.

Please reference these when doing the code:

((random reference))

•>>> import random

•>>> random.randint(1, 100)

•67

((While & if referefence))

•>>> cnum = 3

•>>>while true

•>>> if cnum == 3:

•>>> print(‘correct’)

•>>> break

•>>> elif cnum == 2:

•>>> print(‘incorrect’)

Please post the Python code and the screen shot of your output.

Here is a sample output screen.

What is your guess? 97

Too high

What is your guess? 6

Too low

What is your guess? 82

Too high

What is your guess? 23

Too low

What is your guess? 64

Too high

What is your guess? 46

Too high

What is your guess? 35

Too low

What is your guess? 40

Too high

What is your guess? 37

Too low

What is your guess? 39

Too high

What is your guess? 38

Correct !

>>>

Solutions

Expert Solution

from random import randint

computer = randint(1,100)

guess = 0

while True:

num = int(input("Enter a number between 1 and 100: "))

if num > computer:

    print("Number too High")

elif num < computer:

    print("Number too Low")

else:

    print("Awesome Congratulations !!! you guessed the number in ", guess, "attempts")

    break;

guess = guess + 1

=====================================================

SEE OUTPUT/ CODE FOR INDENTATION

Thanks, PLEASE COMMENT if there is any concern.


Related Solutions

Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
using java For this assignment, you will write a program that guesses a number chosen by...
using java For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to choose a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or...
Create a Guess the Number game. Python randomly chooses a secret four-digit number (with no repeating...
Create a Guess the Number game. Python randomly chooses a secret four-digit number (with no repeating digits) and asks the user to guess it. The user has up to ten attempts to guess the number. After each guess, Python gives the user two clues (until the user either guesses the number correctly or runs out of attempts): The number of digit(s) in the user’s guess that is (are) both correct and in the right position. The number of digit(s) in...
This is done in C++. This is a game where one player thinks of a number...
This is done in C++. This is a game where one player thinks of a number between 1 and a 1000 and the other player has to guess in 10 tries or less. Allow two variations: the computer to pick the number and the player guesses or the player to pick the number and the computer to guesses. 1 – Player one picks a number 2 – Player two guesses the number. 3 – Player one either confirms that the...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses...
(HTML) Write a script that plays a “guess the number” game as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The script displays the prompt Guess a number between 1 and 1000 next to a text field. The player types a first guess into the text field and clicks a button to submit the guess to the script. If the player's guess is incorrect, your program should display...
Please write simple python program with explanation Problem statement: Stock markets are venues where buyers and...
Please write simple python program with explanation Problem statement: Stock markets are venues where buyers and sellers of shares meet and decide on a price to trade.Eddard is very interested in trading in stock market and he started gathering information of one stock.He has projected market prices for that share over the next n months.Eddard wants to purchase and resell the share to earn profits.He is much worried about the loss that might occur so he wanted to calculate "Minimum...
PLEASE USE THE ECLIPSE. I want to make a program that shows whether the correct number...
PLEASE USE THE ECLIPSE. I want to make a program that shows whether the correct number is correct or incorrect. Example: how much is 1+1? option 1: 2 option 2: 3 option 3: 4 option 4: 5 option 5: 6 The answer is 1. because the answer is 2 and the option number is 1. Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT