No products in the cart.

Ask questions which are clear, concise and easy to understand.

Ask Question
  • 1 answers

Kanishk Gupta 3 years, 8 months ago

Padhai krke
  • 1 answers

Gaurav Seth 3 years, 8 months 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
  • 1 answers

Sia ? 3 years, 2 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.

  • 2 answers

A Kumar 3 years, 7 months ago

Tq

Yogita Ingle 3 years, 8 months 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.

  • 1 answers

Meghna Thapar 3 years, 9 months 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

  • 0 answers
  • 3 answers

Anita Kumari 3 years, 8 months ago

None

Mandavi Kushwaha 3 years, 8 months ago

The default return value is NONE.

Khushi Ghangas 3 years, 9 months ago

None
  • 5 answers

Abhijeet Pratap Singh 3 years, 8 months ago

Who are you??

A Kumar 3 years, 8 months ago

Answer of A Kumar is 100+1 percent right

A Kumar 3 years, 8 months ago

f=open ("myfile.txt",'r') x=f.read() print(x) f.close()

Mandavi Kushwaha 3 years, 8 months ago

f= open("myfile.txt","r") l=f.read() for i in l: print (i)

Kanishka Jha 3 years, 9 months ago

File=open("myfile.txt","r") F=File.read() for i in F: print(i)
  • 1 answers

Khushi Ghangas 3 years, 9 months ago

In object oriented programming wrapper class is a class that encapsulates types so that those type can be used to create object instance and method in another class that's need those types.
  • 3 answers

Mandavi Kushwaha 3 years, 8 months ago

By using the open() function

Raju Baghel 3 years, 9 months ago

In the above code also use for loop so it can access all words of impoted file

Himanshu :D 3 years, 9 months ago

F=open(" location of file","r") X=F.read() print(X)
  • 1 answers

Gaurav Seth 3 years, 9 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")

  • 1 answers

Sakshi Tiwari 3 years, 3 months ago

Private access specifier
  • 2 answers

Simran Jeet 3 years, 8 months ago

Kanishka i think the file should be opened in append mode

Kanishka Jha 3 years, 9 months ago

F=open("book","w") F.write("Hello") F.close()
  • 1 answers

Milind Pandey 3 years, 9 months ago

#storing n number of employees in text file. n=int(input("Enter number of employees are::")) ##your text file name in the place of __ remove dash and write the correct name of the file. a=open("___","a") print("now Enter your employees name one by one") for i in range(n): a.write(input("Enter employee name::")) a.close()
  • 1 answers

Sia ? 3 years ago

OSS means Open Source Software refers to software whose source code is available to customers. FLOSS refers to Free/Libre/Open Source Software. It is software that is both free software as well as open-source software. Libre means freedom.
  • 1 answers

Meghna Thapar 3 years, 9 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.

  • 1 answers

Yogita Ingle 3 years, 9 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 App

myCBSEguide

Trusted by 1 Crore+ Students

Test Generator

Test Generator

Create papers online. It's FREE.

CUET Mock Tests

CUET Mock Tests

75,000+ questions to practice only on myCBSEguide app

Download myCBSEguide App