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
ryzh [129]
2 years ago
4

Given the code that reads a list of integers, complete the number_guess() function, which should choose a random number between

1 and 100 by calling random.randint() and then output if the guessed number is too low, too high, or correct.
Import the random module to use the random.seed() and random.randint() functions.

random.seed(seed_value) seeds the random number generator using the given seed_value.
random.randint(a, b) returns a random number between a and b (inclusive).

For testing purposes, use the seed value 900, which will cause the computer to choose the same random number every time the program runs.
Ex: If the input is:
32 45 48 80
the output is:
32 is too low. Random number was 80.
45 is too high. Random number was 30.
48 is correct! 80 is too low.
Random number was 97.

# TODO: Import the random module
import random
def number_guess(num):
# TODO: Get a random number between 1-100
# TODO: Read numbers and compare to random number

if__name__ == "_main_":
# Use the seed 900 to get the same pseudo random numbers every time
random. seed(900)

# Convert the string tokens into integers
user_input = input()
tokens = user_input.split()
for token in tokens:
num = int(token)
number_guess(num)
Computers and Technology
1 answer:
nlexa [21]2 years ago
4 0

Answer:

Following are the code to this question:

import random #import package

def number_guess(num): #define method number_guess

   n = random.randint(1, 100) #define variable n that hold random number

   if num < n: #define if block to check gess number is less then Random number  

       print(num, "is too low. Random number was " + str(n) + ".") #print message

   elif num > n: #check number greater then Random number

       print(num, "is too high. Random number was " + str(n) + ".") #print message

   else: #else block  

       print(num, "is correct!") #print message

if __name__ == '__main__': #define main method

   random.seed(900) #use speed method

   user_input = input() #define variable for user_input

   tokens = user_input.split()  #define variable that holds split value

   for token in tokens: #define loop to convert value into string token  

       num = int(token) # convert token value in to integer and store in num  

       number_guess(num)  # call number_guess method

Output:

33

33 is too low. Random number was 80.

Explanation:

In the above-given python code, first, we import the random package, in the next line, a method number_guess is defined, that accepts num parameter,  in this method, we store the random number in n variable and check the value from the conditional statement.

  • In this, we check value is less than from random number, it will print message too low, and its Random number. otherwise, it will go in the elif section.
  • In this section it will check the value is greater than from a random number, it will print the message to high, and its Random number. otherwise, it will go to else section.
  • In this, it will prints number and it is correct.
  • In the main method, we input value, and use a token variable to convert the value into string token, and then convert its value into an integer, and then call the method number_guess.
You might be interested in
A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
maks197457 [2]
They would all work as they can all run on servers and be set up as networks. Microsoft is not an operating system it is a company that rights the windows operating system.
5 0
2 years ago
1. The precious metals needed to make computer chips, graphic cards, and transistors are found in only a small population of cou
dexar [7]

Answer:

it means that they can charge companies to come mine it making them more wealthy they can also upscale the materials needed to make it as they are the only countries that sell it so they have no one to compete with

3 0
2 years ago
In this lab, you use the pseudocode in figure below to add code to a partially created Python program. When completed, college a
Elza [17]

Answer:

Python code is given below with appropriate comments

Explanation:

#Prompt the user to enter the test score and class rank.

testScore = input()

classRank = input()

#Convert test score and class rank to the integer values.

testScore = int(testScore)

classRank = int(classRank)

#If the test score is greater than or equal to 90.

if(testScore >= 90):

   #If the class rank is greater than or equal to 25,

   #then print accept message.

   if(classRank >= 25):

       print("Accept")

   

   #Otherwise, display reject message.

   else:

       print("Reject")

#Otherwise,

else:

   #If the test score is greater than or equal to 80.

   if(testScore >= 80):

       #If class rank is greater than or equal to 50,

       #then display accept message.

       if(classRank >= 50):

           print("Accept")

       

       #Otherwise, display reject message.

       else:

           print("Reject")

   

   #Otherwise,

   else:

       #If the test score is greater than or equal to

       #70.

       if(testScore >= 70):

           #If the class rank is greater than or equal

           #to 75, then display accept message.

           if(classRank >= 75):

               print("Accept")

           

           #Otherwise, display reject message.

           else:

               print("Reject")

       

       #Otherwise, display reject message.

       else:

           print("Reject")

4 0
2 years ago
You live "out in the middle of nowhere" and feel there is no need to protect your internet connection because there is no one th
Anvisha [2.4K]

Potential uploaded viruses, personal information being lost, blackmail, identity theft.

7 0
2 years ago
A slide in Blake's presentation contained the following information:
deff fn [24]

Answer:

consistent phrasing is missing

Explanation:

If you will note carefully, the bullets are not in correct format. The model is missing. The correct one is as below.

Risks

The correct form of presentation is as below:

1. Risks

a. employees  

              a. physical illness

              b. mental illness

              c. death  

2. Customers  

              a.   complaints

              b.   downtime

3.  Benefits

However, the content seems to be complete now, and hence not anything else is required. And since its not something very tough to decide to go with, bite the bullet is certainly not an issue.  

3 0
2 years ago
Other questions:
  • In a case where electrical current leakage from the circuit occurs, the GFCI would do the following:
    10·1 answer
  • Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map province
    11·1 answer
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $
    14·1 answer
  • Carmina wants to move a paragraph to the right margin of the document she is working in. She moves her cursor to
    8·2 answers
  • Write a program that replaces words in a sentence. The input begins with word replacement pairs (original and replacement). The
    11·1 answer
  • Enter an input statement using the input function at the shell prompt. When the prompt asks you for input, enter a number. Then,
    9·1 answer
  • Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An ho
    12·1 answer
  • 1)When the liquid is spun rapidly, the denser particles are forced to the bottom and the lighter particles stay at the top. This
    10·1 answer
  • It is also called teleconferencing or web conferencing,which is an online meeting wherein two or more people can see,hear,and ta
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!