Need 2.5 Code Practice Answers

The new education question and answer asked students to express what they think is the most important thing for a student to do if they wanted to become success. The one that response stood out from the rest was practice. People who surely are successful do not become successful by being born. They work hard and perseverance their lives to succeeding. If you wish to get your goals, keep this in mind! following are one of the answer and question example that you may possibly make use of to practice and improve your knowledge and also give you insights that might just guide you to preserve your study in school.

Question:

Need 2.5 Code Practice Answers

Copy and paste the following code into the sandbox window. Modify the code so that user is asked to multiply two random numbers from 1 to 10 inclusive.
import random
random.seed()
# TODO: Update the following two lines with a call to a function
# from the random library that generates a random number between
# 1 and 10, inclusive.
a = 6 # HINT: Replace 6 with a function call
b = 3 # HINT: Replace 3 with a function call
print (“What is: ” + str(a) + ” X ” + str(b) + “?”)
ans = int(input(“Your answer: “))
if (a * b == ans):
print (“Correct!”)
else:
print (“Incorrect!”)

Answer:

Using the randint() function in python, we can generate a random integer number within a stated range of integer values. The required lines of code are :

  • a = random.randint(1, 11)
  • b = random.randint(1, 11)
  • The random.randint() function is given two arguments which are the lower and upper boundaries of the integer we want to generate.
  • While the lower integer, 1 is included in the integer that could be generated, 11 is not inclusive
  • Therefore, the function only generates a random integer value between the values (1 and 10) for each variable.
READ MORE  A 15-foot flagpole leans slightly, such that it makes an 80° angle with the ground. The shadow of the flagpole is 10 feet long when the sun has an unknown angle of elevation. How could the angle of elevation of the sun, x, be determined?

Therefore, the running code :

a = random.randint(1, 11)

b = random.randint(1, 11)

print(“What is: ” + str(a) + ” X ” + str(b) + “?”)

ans = int(input(“Your answer: “))

if(a * b == ans):

print(“Correct!”)

else:

print(“Incorrect!”)

They can certainly hopefully help the student take care of the question by applying the questions and answer examples. You possibly will then have a discussion with your classmate and continue the school learning by studying the topic to one another.

Leave a Reply

Your email address will not be published.