Sunday 15 April 2012

python - Restricting characters of a string -



python - Restricting characters of a string -

i having problems trying write program, takes in input (string) , checks amount of characters in string. string should able tell wether message contains on or under 160 characters. have written code, not run. can help me? best guess utilize len() function , if or else statement. right way of doing it? , how create if , else statement know, number i'm getting len() the number of characters?

i hope makes bit of sense...

as probable have guessed, pretty new @ python... hope understand question, else sense free ask!

my code:

def characterrestriction(): print("welcome chat. maximun amount of characters is: 160") len(message) = input("enter message:") print ("the lenght of message is:", len(message)) if len(message) <= 160: print(message) else: len(message) > 160 print ("maximum amount of characters 160") characterrestriction()

method after correcting:

def characterrestriction(): print("welcome chat. maximun amount of characters is: 160") message = input("enter message:") print ("the lenght of message is:", len(message)) if len(message) <= 160: print(message) else: print("maximum amount of characters 160")

python character

No comments:

Post a Comment