[Tutor] (no subject)

Alan Gauld alan.gauld at yahoo.co.uk
Sun Mar 14 10:46:40 EDT 2021


On 14/03/2021 11:53, ੧ wrote:
> Respected sir, please guide me with the question given below. I don't fully
> understand the question.

What parts do you not understand? What parts do you understand?


> Write a python program to read from input a string. 

Do you know how to do that?
Consider the input() function.

> The input contains COMMA separated string values. 

Do you know how to separate a string into separate fields?
Consider the string.split() method.

> The output of the program is the count of
> string values where (a) the length is >= 2; 

Do you know how to find the length of a string
Consider the len() function

Do you know how to increment a counter for a condition?
Consider the if construct and addition operator

AND (b) the first and last
> character of the string value are the same. 

Do you know how to extract the first and last characters of a string?
Consider indexing

Do you know how to logically combine tests (with AND in this case?)
Consider the boolean operators.


> Input: abc,xyz,aba,1221,1
> Output: 2 

Do you understand why the output is 2?
Can you write code that produces that result?

Input: abc, xyz , alpha Output: 1 [Note that the second string (
> xyz ) has SPACE at the start and at the end; while the last string ( alpha)
> has SPACE only at the start.

Including spaces as part of the fields is sneaky but does
not, in practice, make things any more easy or difficult.

Note that we do not do homework for you, but we will review
your code and offer suggestions(as above0 to help you do
your homework.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list