Question

fac = 1; for i in range(1, 3): fac *= i print(fac) (Python) please explain why...

fac = 1;
for i in range(1, 3):
fac *= i
print(fac)

(Python)

please explain why the answer is two and how to change it to other values like 4 or 5

please be complete and act as if you were explaining it to a small lost child

ty

0 0
Add a comment Improve this question Transcribed image text
Answer #1
This code computes product of numbers from 1 to n
Where n is the second argument of range - 1

This code computes the factorial of 2
So, answer is 1*2 = 2

if we change the number from 3 to 4
the it computes 1*2*3 = 6

if we change the number from 3 to 5
the it computes 1*2*3*4 = 24

if we change the number from 3 to 6
the it computes 1*2*3*4*5 = 120

the factorials in sequence are 1, 2, 6, 24, 120, .... 
There is no way to get 4 or 5 in the sequence 
Add a comment
Know the answer?
Add Answer to:
fac = 1; for i in range(1, 3): fac *= i print(fac) (Python) please explain why...
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
  • PYTHON: Im stuck here, big O notation and runtime. What is it and Why are they...

    PYTHON: Im stuck here, big O notation and runtime. What is it and Why are they those? Please look at the pic, need help as Im confused. Thank You! def method3(n): for i in range(n): for j in range(100): for k in range(n): print(i+j+k) What is the runtime (tightest/closest bound in terms of O) for the above python function (method 3)? Please briefly explain. Enter your answer here def method4(n): for i in range(n): for j in range(n, o, -2):...

  • This is in python. I need to print out a specific message depending on the number...

    This is in python. I need to print out a specific message depending on the number that's input. for example, if the user inputs 1, program should print out "hello". if the user inputs 2, program should print out "hi". But also the program should keep asking for a number to be input after a valid number is input. For example, user inputs 1, program prints out "hello" and then asks the user to input another value. but also the...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • # Python Please help me convert the input values to float values Code works, but the...

    # Python Please help me convert the input values to float values Code works, but the values printed need to be floats like 77.0 etc.    j_list = [] k_list = [] c_list = []    # Enter scores for Jean print("Please enter Jean's scores one by one. ") for i in range(4): j_list.append(eval(input())) print("Jeans scores:", j_list)    # Enter scores for Kayla    print("Please enter Kayla's scores one by one. ") for i in range(4): k_list.append(eval(input())) print("Kayla scores: ",...

  • I am using python and I want to know how I can get the spacing between...

    I am using python and I want to know how I can get the spacing between the low mid and high to be dependent on the range and how I can get that boarder to be dependent on the range as well. Im not sure what you mean, I just want to know about the spacing. Modify your project1.py Python program so that it displays the low, mid and high point values for periodic function and a double-line border. (HINT:...

  • I need help with this python programming exercise, please! thanks in advance Create a Python script...

    I need help with this python programming exercise, please! thanks in advance Create a Python script file called hw4.py. Add your name at the top as a comment, along with the class name and date. Both exercises should be in this file, with a comment before each of them to mark it. Ex. 1. Write a program that inputs an integer number from the user, then prints a letter "O" in ASCII art using a width of 5 and the...

  • Consider the following python code that will sort the list of numbers using the Bubble Sort...

    Consider the following python code that will sort the list of numbers using the Bubble Sort algorithm def bubbleSort(alist): print(alist) for j in range (len(alist) - 1, 8, -1): for i in range(): if alist[i] > alist[i + 1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp print(alist) alist = [52, 25, 94, 17, 25, 52] bubbleSort (alist) print(alist) Sort the following series of values into ascending order using the Bubble Sort algorithm. Write out the complete row of...

  • 1. Extending the answer from Python HW #7 for question #1, write the following python code...

    1. Extending the answer from Python HW #7 for question #1, write the following python code to expand on the Car class. Include the python code you developed when answering HW #7. Add class “getter” methods to return the values for model, color, and MPG Add class “setter” methods to change the existing values for model, color, and MPG. The value to be used in the methods will be passed as an input argument. Add class method that will calculate...

  • // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in...

    // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in Python (in a .py file) that: Makes two lists of 50 numbers each, where the first list is multiples of 5, and the second list is the first 50 squares: 1, 4, 9, 16, 25, 36, ....up to 2500. then I want you to make a third list by multiplying each individual pair in the two lists, so for example: 5 times 1 is...

  • Python: Could you please say step by step how the output is coming? I understand about...

    Python: Could you please say step by step how the output is coming? I understand about importing and getting random number but how the inner loop is working? Code: import random li1 = [[random.randrange(5) for i in range(3)] for j in range(4)] print("First output : {}".format(li1)) ncol = 4 nrow = 5 li2 = [ [random.randrange(2) for i in range(ncol) ] for j in range(nrow) ] print("Second output : {}".format(li2)) Output: First output : [[3, 2, 4], [2, 3, 2],...

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