Ask questions which are clear, concise and easy to understand.
Ask QuestionPosted by Keerthi Keerthi 4 years, 1 month ago
- 1 answers
Posted by Nabaneet Das 4 years, 1 month ago
- 1 answers
Gaurav Seth 4 years, 1 month ago
Find factorial using Python function – using for loop
#Pyton program to find factorial of a number
def factorial(num):#function definition
fact=1
for i in range(1, num+1):#for loop for finding factorial
fact=fact*i
return fact #return factorial
number=int(input("Please enter any number to find factorial: "))
result=factorial(number)#function call and assign the value to variable result
print("The factorial of %d = %d"%(number,result))
When the above code is executed, it produces the following results
Please enter any number to find factorial: 6
The factorial of 6 = 720
Find factorial using Python function – using while loop
def factorial(num):#function definition
fact=1;
i=1
while i<=num:
fact=fact*i
i=i+1
return fact
num=input("Enter a number..");
result=factorial(num)
print("factorial of the number: %d" %result)
factorial(num)#function call
When the above code is executed, it produces the following results
Enter a number..5
factorial of the number: 120
Programming approaches for implementing these program
- Take a number as input from the user and stored in variable number for finding factorial
- Declare a python function to find factorial
- Inside the function, declare the variable fact and initialise as 1
- Inside the function, find the factorial of a given number using for loop in Python
- Run the loop from given number until 1 and multiply numbers
- Call the factorial() function and assign the output to variable result
- the factorial of the given number is displayed using the print() function in Python
Posted by Deepak Farswan 4 years, 1 month ago
- 0 answers
Posted by Rupali Mane 3 years, 6 months ago
- 1 answers
Sia ? 3 years, 6 months ago
operator is used to get hidden names due to variable scopes so that you can still use them. The scope resolution operator can be used as both unary and binary. You can use the unary scope operator if a namespace scope or global scope name is hidden by a particular declaration of an equivalent name during a block or class. For example, if you have a global variable of name my_var and a local variable of name my_var, to access global my_var, you'll need to use the scope resolution operator.
Posted by A Kumar 4 years, 1 month ago
- 2 answers
Yogita Ingle 4 years, 1 month ago
Python file method flush() flushes the internal buffer, like stdio's fflush. This may be a no-op on some file-like objects.
Python automatically flushes the files when closing them. But you may want to flush the data before closing any file.
Posted by Mandavi Kushwaha 4 years, 1 month ago
- 0 answers
Posted by Kanishka Jha 4 years, 1 month ago
- 1 answers
Meghna Thapar 4 years, 1 month ago
Accessing a binary file from a C++ program (by not using the old C functions) requires firstly attaching a stream variable to the file. The usual stream classes ofstream (output file stream) and ifstream (input file stream) are still the types of streams to use. A an additional type called an fstream is provided which allows for files that can be written to and read from if this is a desirable property (in the design of database type programs, this is often the case).
Before any operation can take place on a file, it of course must be <i>opened</i>, and when you are finished with the file, it should be closed to avoid loss of data.
Opening a Stream
Posted by Dr. Sakshi Vashisht 4 years, 1 month ago
- 0 answers
Posted by Ishika Jagatramka 4 years, 1 month ago
- 3 answers
Posted by Suba Sri 4 years, 1 month ago
- 0 answers
Posted by Abhijeet Pratap Singh 4 years, 1 month ago
- 5 answers
Mandavi Kushwaha 4 years, 1 month ago
Kanishka Jha 4 years, 1 month ago
Posted by Gayathri M 4 years, 1 month ago
- 1 answers
Khushi Ghangas 4 years, 1 month ago
Posted by Eifa Khan 4 years, 1 month ago
- 0 answers
Posted by Kawaljot Kaur 4 years, 1 month ago
- 0 answers
Posted by Teesha Sharma 4 years, 1 month ago
- 3 answers
Raju Baghel 4 years, 1 month ago
Posted by Swatantra Tyagi 4 years, 1 month ago
- 1 answers
Swatantra Tyagi 3 years, 10 months ago
Posted by Khushi Ghangas 4 years, 2 months ago
- 1 answers
Gaurav Seth 4 years, 2 months ago
Source Code: Using if...elif...else
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Source Code: Using Nested if
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Posted by Sakshi Tiwari 4 years, 2 months ago
- 1 answers
Posted by Nandhini J 4 years, 2 months ago
- 2 answers
Simran Jeet 4 years, 1 month ago
Posted by Allen Joe S Alapat 4 years, 2 months ago
- 1 answers
Milind Pandey 4 years, 2 months ago
Posted by Ankita Shrivastav 3 years, 5 months ago
- 1 answers
Sia ? 3 years, 5 months ago
Posted by Abhishek Bhandari 4 years, 2 months ago
- 1 answers
Meghna Thapar 4 years, 2 months ago
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number. Basically in python range(n) iterates n times, which is of exclusive nature that is why it does not give last value when it is being printed, we can create a function which gives inclusive value it means it will also print last value mentioned in range.
Posted by Khushi Rawat 4 years, 2 months ago
- 0 answers
Posted by Neeraj Meena 4 years, 2 months ago
- 0 answers
Posted by Deepak . 4 years, 2 months ago
- 1 answers
Yogita Ingle 4 years, 2 months ago
Interspace is a client/server software program that allows multiple users to communicate online with real-time audio, video and text chat in dynamic 3D environments. Interspaceprovides the most advanced form of communication available on the Internet today.
The Interspace is a vision of what the Internet will become, where users cross-correlate information in multiple sources. It is an applications environment for interconnecting spaces to manipulate information, much as the Internet is a protocol environment for interconnecting networks to transmit data.
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app
Kanishk Gupta 4 years, 1 month ago
7Thank You