1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ipatiy [6.2K]
3 years ago
7

Modify the guessing-game program so that the user thinks of a number that the computer must guess.

Computers and Technology
1 answer:
Triss [41]3 years ago
7 0

Answer:

import random

import math

smaller = int(input("Enter the smaller number: "))

larger = int(input("Enter the larger number: "))

count = 0

print()

while True:

   count += 1

   myNumber = (smaller + larger) // 2

   print('%d %d' % (smaller, larger))

   print('Your number is %d' % myNumber)

   choice = input('Enter =, <, or >: ')

   if choice == '=':

       print("Hooray, I've got it in %d tries" % count)

       break

   elif smaller == larger:

       print("I'm out of guesses, and you cheated")

       break

   elif choice == '<':

       larger = myNumber - 1

   else:

       smaller = myNumber + 1

Explanation:

The code to be Modified is as indicated below:

# Modify the code below:

import random

smaller = int(input("Enter the smaller number: "))

larger = int(input("Enter the larger number: "))

myNumber = random.randint(smaller, larger)

count = 0

while True:

   count += 1

   userNumber = int(input("Enter your guess: "))

   if userNumber < myNumber:

       print("Too small")

   elif userNumber > myNumber:

       print("Too large")

   else:

       print("You've got it in", count, "tries!")

       break

Detailed Explanation:

Line 3 and 4 of the codes prompts the user to enter a smaller and larger number. Line 5 we initiate the formula for minimum number of guesses. Line 14 and 17 prints out the output  I'm out of guesses, and you cheated and Hooray, I've got it in X after validating the conditions.

You might be interested in
This isn't academic, but what do I do if HI-REZ won't let me sign into an existing account. “Something went wrong” keeps popping
NNADVOKAT [17]

Answer:

contact their support

Explanation:

6 0
3 years ago
Graph the functions 8n, 4nlogn, 2n
sukhopar [10]

Graphs are used to represent functions and equations

<h3>How to graph the functions</h3>

The expressions of the functions are given as:

8n, 4nlog(n), 2n^2. n^3 and 2^n

Rewrite the expressions as functions.

So, we have:

y = 8n

y = 4nlog(n)

y = 2n^2

y = n^3

y =  2^n

Next, we plot the graph of the functions

See attachment for the graph of the functions, where n is represented on the x-coordinate, and y is represented on the y-coordinate

Read more about graphs and functions at:

brainly.com/question/13473114

4 0
2 years ago
What appears in the document after you have inserted a video?
Nitella [24]

Answer:

text with a hyperlink to the video website

Explanation:

documents do not auto-upload thumbnails or embedded videos for playback, so external links are pasted there

6 0
3 years ago
Read 2 more answers
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==&gt; Close All Projects).
Nutka1998 [239]

Answer:

// name of the package

package stringlength;

// Scanner is imported but it is not needed

// So it is commented

// import java.util.Scanner;

// The class name StringLength is defined

public class StringLength {

// main method to signify the beginning of program execution

public static void main(String[] args) {

// if-statement to check if argument is supplied to

// command line

if(args.length > -1) {

// the first argument is read and assigned to input

String input = args[0];

int length = input.length(); // using length() method in String class

System.out.println("Your string has a length of "+length+" characters.");

} else {

System.out.println("Please enter your string argument in quote");

}

}

}

Explanation:

The code works fine with little modification and comments. The user should supply the string arguments in quote. The quote must surround the strings because our logic read the first argument passed to the command line. Inserting a string with space between them will provide a wrong output.

A sample image is attached.

6 0
3 years ago
By what date must federal taxes typically be filed and sent to the IRS?
marishachu [46]
April 15th of each annual year
6 0
4 years ago
Other questions:
  • Which argument forces a writer to return to and change the input before resolving a “UnicodeError”?
    10·1 answer
  • Some might consider careers in the Construction industry to be quite flexible. Which statement supports this claim? Employees ca
    14·2 answers
  • Which of the following is a malicious program that can replicate and spread from computer to computer?
    8·2 answers
  • ____ allow us to store a binary image in code. (1 point)
    9·1 answer
  • Although implementations vary, reader–writer locks usually block additional readers if a lock is already held in read mode and a
    13·1 answer
  • When drawing multiple objects on the same slide they cannot overlap<br> true<br> false
    8·2 answers
  • Task 1: Alex has created the following code using Scratch and expected it to move backwards and forwards across the screen. Howe
    13·1 answer
  • Before a new email application could be released to the public, it was released for a few days to some account holders of a webs
    14·2 answers
  • Select the correct answer from the drop-down menu.
    15·2 answers
  • What should you commit to your family members?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!