Write a Python program, initially with the following code in it: import random #
ID: 3695620 • Letter: W
Question
Write a Python program, initially with the following code in it:
import random
# A sequence of assignments to generate a random problem:
a = 0
b = 0
c = 0
d = 0
e = 0
u = 0
v = 0 print( ' Problem: ({a}x + {b}) + {c}({d}x + {e}) = ? ' .format(a = a, b = b, c = c, d = d, e = e))
print( ' Answer: {u}x + {v} ' .format(u = u, v = v))
Then change the sequence of assignments in the middle so that the program, when run, creates and prints a random polynomial simplication problem. (You may need additional variables.) Your code should guarantee that all of the coeffcients in the problem are single-digit integers and that all coeffcients in the answer are positive two-digit integers.
Explanation / Answer
#!/usr/bin/python
import random
# A sequence of assignments to generate a random problem:
a = random.randrange(0,9)
b = random.randrange(0,9)
c = random.randrange(0,9)
d = random.randrange(0,9)
e = random.randrange(0,9)
u = random.randrange(10,99)
v = random.randrange(10,99)
print( ' Problem: ({a}x + {b}) + {c}({d}x + {e}) = ? ' .format(a = a, b = b, c = c, d = d, e = e))
print( ' Answer: {u}x + {v} ' .format(u = u, v = v))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.