Question

import random x = 10 y = random.randint(5, 21) print(x + y) how is 15 the answer?

import random
x = 10
y = random.randint(5, 21)
print(x + y)

how is 15 the answer?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

random.randint(5, 21) generates a random number between 5 and 21 including 5 and 21
So random.randint(5, 21) randomly generates a number from the following set [5,6,7,8,9,.......,19,20,21]
Hence when you run the code , It may possible that the random number generated , y = 5
Since x=10 , Ans = 10+5 = 15

In the screenshot uploaded , I have run the code several times , as you can see there are different values possible
When result is 15, you can see the value of y = 5.

CAUsers/Rogue/Uesktop/chega/pixel art- Spyder (Python 3.7) Eile Edit Search Source Bun Debug Consles Projects Tools View HelpVariable explorer Name Type Size Value int 1 10 X int 1 5 y Variable explorer File explorer Help IPython console Console 3/AX

Add a comment
Know the answer?
Add Answer to:
import random x = 10 y = random.randint(5, 21) print(x + y) how is 15 the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...

    FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess:     if int(YourNumber) == number:         print("YAY, You have guessed my number")     else:         unusedguesses=int(guess)-1         if unusedguesses == 0:              break         else:             print("Try again!") print("The number was ", str(number))

  • How to remove all occurrences of 2 from list2. Then display the list. Python import random...

    How to remove all occurrences of 2 from list2. Then display the list. Python import random list1 = [] for i in range (10): list1.append(random.randint(1,4)) print('List 1:') print(list1) list2 = [] list2.append(list1[5:]) print('List 2:') print(list2) list2.remove ******** (This is the part I am having trouble on!!) print('List 2 with all 2s removed:') print(list2) Sample output: List 1: [4, 1, 1, 3, 3, 3, 2, 4, 2, 4] List2: [3, 2, 4, 2, 4] List 2 with all 2s removed: [3,...

  • import random fave_word = 'hello' # add 'world' and a random number (between 0-3) of 'Bob's...

    import random fave_word = 'hello' # add 'world' and a random number (between 0-3) of 'Bob's to this word fave_word += "world" rand_num = random.randint(0,3) if rand_num == 0: fave_word += '' elif rand_num == 1: fave_word += 'Bob' elif rand_num == 2: fave_word += 'BobBob' elif rand_num == 3: fave_word += 'BobBobBob' else: fave_word += '' print(fave_word) Looking for a way to turn this into a function and cut down on redundant code. (python)

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • ## python oop creating a large number of instances ## im trying to create a large...

    ## python oop creating a large number of instances ## im trying to create a large number of instances for a class. could you show me a way to make it work import math import random class soldiers: def __init__(self,x,y): self.x = x self.y = y def get_target(self,x,y,number_red_soldiers,number_blue_soldiers): pass # self.target = def aiming_angle(self,x,y,target,enemy_x,enemy_y): dy = self.y-enemy_y[target] dx = self.x-enemy_x[target] angle =math.atan(dy/dx) a = 0 number_blue_soldiers= 10 number_red_soldiers = 10 for i in range(number_blue_soldiers): blue_x = random.randint(0,100,10) blue_y = random.randint(0,100,10)...

  • Try to get the code down to less than 40 lines. (PYTHON) import random fave_number =...

    Try to get the code down to less than 40 lines. (PYTHON) import random fave_number = 1 # doing some calculations on this number new_fave = fave_number + fave_number new_fave = new_fave * 2 new_fave = new_fave ** 5 new_fave = new_fave + 123456 print(new_fave) # check if new_fave is divisible by 5 div_by_5 = False if (new_fave % 5 == 0): div_by_5 = True else: div_by_5 = False    if (div_by_5 == True): print("Is new fave number divisible by...

  • Question 21 If x = 10 and y = 20, which expression is True? x==y y!-2*x...

    Question 21 If x = 10 and y = 20, which expression is True? x==y y!-2*x y >= x y<= x U Question 22 What is x's final value? X = 10 y = 20 if y <2 X: X = X + 5 else: X = X * 2 20 15 25 10

  • ## python pandas # i want to print ALL of the columns import quandl import math...

    ## python pandas # i want to print ALL of the columns import quandl import math import pandas as pd df = quandl.get('WIKI/GOOGL') df['HL_PCT'] = df['Adj. High'] - df['Adj. Low']/ df['Adj. Close'] df['PCT_CH'] = df['Adj. Close'] - df['Adj. Open']/ df['Adj. Open'] print(df.head()) thon 3.7.0 Shell workthrough 1.p. X Edit Shell Debug Options Window Help РСт CH File Edit Format Run Options Adi, Volume Open High Low HL_PCT .. Heln dow 2004-08-19 100.01 104.06 95.96 44659000.0 51.234713 49.322842 quandl import math...

  • : back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von...

    : back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von AwNP Complete the get_message function so if user_num is equal to rand_num, return "You picked the same number as the computer!" if user_num is less than rand_num, return "Your number is smaller than the computer's number." if user_num is greater than rand_num, return "Your number is higher than the computer's number." Comment out the call to main when trying to pass the tests. 11...

  • Python 19. Jonathan wants to print out a random integer from -10 to 10. We wrote...

    Python 19. Jonathan wants to print out a random integer from -10 to 10. We wrote the program as follows. Please help him correct the code. import random print(random_integer(10,-10))

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT