Search code examples
pythonpython-2.7raw-input

Input from keyboard in python


I write a simple factorial function in python to know the factorial of n . As like we given n and it shows the factorial of n . But the problem is , i use raw_input function to get the value of n. But can't work with that . What can i do to do with raw_input ?


Solution

  • You need to cast the default string type to int

    val = raw_input()    #val accepts a string 
    
    val = int(raw_input())   #val takes integer input