answer.
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]
1 year 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]1 year 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
Consider the following 3-PARTITION problem. Given integers a1; : : : ; an, we want to determine whether it is possible to partit
ZanzabumX [31]

Answer:

Explanation:

Find attach the solution

6 0
1 year ago
An app builder has created a report for sales people to view records from the custom object, some users have complained that the
Mila [183]

Answer:

There is a need for some people to see the total transparency of the records that are meant to be shared with a select group of people. There are certain things that can be done for this. The first one is that the sharing rules should be checked. To whom are the details shared with. The next one is the filters that are used.

These can be reported and changed accordingly. Lastly, the whole organization’s defaults can be checked. This is something that can be done when the previous methods that were done did not work that well. Once some changes are done, the people can check if they already work and if the records can be viewed.

Explanation:

8 0
1 year ago
Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the elemen
Xelga [282]

Answer:

The JAVA program to implement for loop for given scenario is shown below.

public class MyProgram {

   public static void main(String args[]) {    

     int len = 5;

     int[] lowerScores = new int[len];      

     lowerScores[0] = 5;

     lowerScores[1] = 0;

     lowerScores[2] = 2;

     lowerScores[3] = -3;      

     System.out.println("The original elements of array are ");

     for(int i=0; i<len; i++)

     {

         System.out.print(lowerScores[i]+" ");

     }      

     System.out.println();

     System.out.println("The modified elements of array are ");

     for(int i=0; i<len; i++)

     {

         // if element is 0 or negative, 0 is assigned to this index

         if(lowerScores[i] <= 0)

           lowerScores[i] = 0;

       // 1 is subtracted from every non zero and positive element

         else

           lowerScores[i] = lowerScores[i] - 1;

           

       System.out.print(lowerScores[i]+" ");

     }

   }

}

OUTPUT

The original elements of array are  

5 0 2 -3 0  

The modified elements of array are  

4 0 1 0 0

Explanation:

The integer array is declared as shown.

int[] lowerScores = new int[len];

The length of the array is given by integer variable len. As per the question, we have taken four elements and size of 5 for the given array.

int len = 5;

The elements of the array are initialized inside the program with the elements given in the question.

lowerScores[0] = 5;

      lowerScores[1] = 0;

The values of the array can be changed to test the program. Also, the size of the array can be changed for testing.

As per the given scenario, if the element is greater than zero, 1 is subtracted from this element. For elements less than or equal to zero, that particular element is assigned the value of 0.

The given program implements if else statement inside for loop for this purpose.

for(int i=0; i<len; i++)

     {

         // if element is 0 or negative, 0 is assigned to this index

         if(lowerScores[i] <= 0)

           lowerScores[i] = 0;

       // 1 is subtracted from every non zero and positive element

         else

           lowerScores[i] = lowerScores[i] - 1;

     }  

5 0
1 year ago
Read 2 more answers
Drag each tile to the correct box.
garri49 [273]
I think select the video insert select the movie option under illustrations resize the video player then select the insert tab i’m not 100 percent sure tho
8 0
2 years ago
Read 2 more answers
Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the given program:
ohaa [14]

Answer:

Following are the correct code to this question:

short_names=['Gus','Bob','Zoe']#defining a list short_names that holds string value

print (short_names[0])#print list first element value

print (short_names[1])#print list second element value

print (short_names[2])#print list third element value

Output:

Gus

Bob

Zoe

Explanation:

  • In the above python program code, a list "short_names" list is declared, that holds three variable that is "Gus, Bob, and Zoe".
  • In the next step, the print method is used that prints list element value.
  • In this program, we use the list, which is similar to an array, and both elements index value starting from the 0, that's why in this code we print "0,1, and 2" element value.
7 0
1 year ago
Other questions:
  • In an ethernet network, the signal that is sent to indicate a signal collision is called a ________ signal.
    7·1 answer
  • Why is it important to back up data on a computer before you burn-in test the cpu?
    9·1 answer
  • In its simplest form, communication is defined as ________.
    7·1 answer
  • Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
    14·1 answer
  • In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
    14·1 answer
  • Represent the logic of a program that allows the user to enter a value for one edge of a cube. The program calculates the surfac
    10·1 answer
  • Write a recursive method called printNumPattern() to output the following number pattern. Given a positive integer as input (Ex:
    5·1 answer
  • Which of the following sorting algorithms is described by this text? "Take the item at index 1 and see if it is in order compare
    10·1 answer
  • While Angela is making modifications to Katie’s Word document, she would like to inform Katie of the reasoning for the change. W
    10·1 answer
  • Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!