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
ryzh [129]
4 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]4 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
What is the maximum number of charters of symbols that can be represented by UNicode?
Sati [7]

Answer: 16 bit

Explanation:

4 0
4 years ago
A technology _____ begins with the birth of a new technology and ends when that technology reaches its limits and dies as it is
Aleks04 [339]
A technology cycle begins with the birth of a new technology and ends when that technology reaches its limits and dies as it is replaced by a newer, substantially better technology.
5 0
4 years ago
Given integer variables totalTickets, vipTickets, and sessionNum, which line of code correctly calls the following function? voi
alekssr [168]

Given integer variables <em>'totalTickets, vipTickets, and sessionNum'</em>, the line of code given in option C correctly calls the following function: "<em>void FinalTally(int* totalAttendees, int* vipAttendees, int numSessions);</em>"

The correct function call with the variables named <em>'totalTickets, vipTickets, and sessionNum</em>' is as follows:

<em>FinalTally(&totalTickets, &vipTickets, sessionNum); </em>

A function call refers to an expression that passes control and arguments (if there are any) to the specified function and has the syntax as <em>FunctionName (argumentList</em>) where <em>FunctionName is the name of the function to be called and argumentList indicates the list of arguments (separated by commas) to be passed to the calling function</em>.

"

<u><em>Correct question is as follows:</em></u>

Given integer variables totalTickets, vipTickets, and sessionNum, which line of code correctly calls the following function? void FinalTally(int* totalAttendees, int* vipAttendees, int numSessions);

a. FinalTally(totalTickets, vipTickets, &amp;session Num);

b. FinalTally(&amp;totalTickets, &amp;vipTickets, session Num);

c. FinalTally(&totalTickets, &vipTickets, sessionNum);

d. FinalTally(&amp;totalTickets, &amp;vipTickets, &amp;session Num);

"

You can leran more about Function Call at

brainly.com/question/28566783

#SPJ4

3 0
1 year ago
Explain 2 ways in which data can be protected in a home computer??
Nonamiya [84]

Answer:

The cloud provides a viable backup option. ...

Anti-malware protection is a must. ...

Make your old computers' hard drives unreadable. ...

Install operating system updates. ...

3 0
3 years ago
Mm
Luba_88 [7]

Answer:

Print Area

Explanation:

First, I'll assume Donte is making use of a spreadsheet application (Microsoft Office Excel, to be precise).

From the given options, only "Print Area" fits the given description in the question.

The print area feature of the Excel software allows users to print all or selected workbook.

To print a selection section, Donte needs to follow the steps below.

Go to File -> Print.

At this stage, Donte will have the option to set the print features he needs.

Under settings, he needs to select "Print Selection"; this will enable him Print sections of the entire workbook.

Refer to attachment for further explanation

8 0
3 years ago
Other questions:
  • Add a checkbox associated with each label. The first checkbox should have name and id of "likeCats" and be initially checked. Th
    5·1 answer
  • PLS HELP!!
    13·1 answer
  • As a safe driver, you cannot, __________
    13·1 answer
  • Which of the following is NOT something you can specify in the bullets and numbering dialog box?
    8·1 answer
  • A series of four or five comparisons and calculations that together determine an employee's withholding tax value might be group
    6·1 answer
  • Write a perl program that reads from a file containing a list of names and then displays that list to a user. The program should
    11·1 answer
  • 4. True or False: In order to use wi-fi signal/network, you have to remain seated in one spot.
    6·1 answer
  • Sự ra đời của thương mại điện tử có tác động như thế nào đến việc quảng cáo và Marketing sản phẩm
    11·2 answers
  • An employee is working on building a new computer application for a friend. For this purpose, he uses the software that is regis
    5·1 answer
  • Write, compile, and test the MovieQuoteInfo class so that it displays your favorite movie quote, the movie it comes from, the ch
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!