0

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 ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
tanzir
  • 31
  • 2

2 Answers2

1

Your factorial function probably takes an integer as input.

However, raw_input returns a string.

So you either need to convert the returned string to an integer. By using int().

Or you can directly use input() which returns an integer in Python2.

Ayush Mishra
  • 506
  • 1
  • 4
  • 15
0

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
XZ6H
  • 1,779
  • 19
  • 25