While loop python resulting in infinite loop -


def generate_n_chars(n,s="."):     res=""     count=0     while count < n:         count=count+1         res=res+s      return res  print generate_n_chars(raw_input("enter integer value : "),raw_input("enter character : ")) 

i beginner in python , don't know why loop going infinity. please correct program

the reason because input evaluated , set string. therefore, you're comparing 2 variables of different types. need cast input integer.

def generate_n_chars(n,s="."):   res=""   count=0   while count < n:     count=count+1     res=res+s  generate_n_chars(int(raw_input("enter integer value : ")),raw_input("enter character : ")) 

Comments

Popular posts from this blog

javascript - Replicate keyboard event with html button -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Web audio api 5.1 surround example not working in firefox -