Q. Write a program that inputs a word and prints "Yes it starts !!" if the given word starts with "0", "1", "2", ... , "9".
Answer :-
str = input ("Enter the word :- ") if str[0].isdigit() : print ("Yes it starts !!" ) else : print("The string does not start with 0, 1, 2, ... , 9")
Output :-
Enter the word :- 05Path
Yes it starts !!
>>>
Yes it starts !!
>>>
Enter the word :- Path Walla
The string does not start with 0, 1, 2, ... , 9
>>>
The string does not start with 0, 1, 2, ... , 9
>>>
Enter the word :- 9Walla
Yes it starts !!
>>>
Yes it starts !!
>>>
Could you explain why the [0] goes there?
ReplyDelete??
DeleteIts the 0th index of the string provided by the user
DeleteYes,
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )