It’s my first semester as a CSE student. I have a course that teaches Python. I understand basics. But when it comes to solving questions like the ones shared, I literally can’t do anything. Is it from a lack of practice? or did I miss some kind of manual. Can anyone recommend me any book or website that teaches how to approach or solve these kinds of questions. I’m getting very demotivated from constant failure.
Don’t worry. These are questions from my previous quizes.
𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 1: Write a python program that will run a loop until the user gives the input “STOP”. Then based on the user inputs print the pattern as shown in the examples. The output should be printed AFTER the END OF GIVING INPUT. (You are not allowed to use String multiplication for this task) ================================ Sample Input 1: a b c d STOP Sample Output 1: aaaa bbb cc d Explanation of Output 1: Here use gives 4 inputs before “STOP” so the output consists of 4 lines. The first input was ‘a’ so the program prints ‘aaaa’ in the first line. The second input was ‘b’ so the program prints ‘bbb’ in the second line. The third input was ‘c’ so the program prints ‘cc’ in the third line. The fourth input was ‘d’ so the program prints ‘d’. ================================ Sample Input 2: a b c STOP Sample Output 2: aaa bb c Explanation of Output 2: Here use gives 3 inputs before “STOP” so the output consists of 3 lines. The first input was ‘a’ so the program prints ‘aaa’ in the first line. The second input was ‘b’ so the program prints ‘bb’ in the second line. The third input was ‘c’ so the program prints ‘c’ in the third line.
𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 2: Take a word and a single character as user inputs. Print “Yes” if and only if the word starts and ends with the character and the character is not present anywhere in the rest of the word. Otherwise, print “No”. (You are not allowed to use any built-in function including count() for string except len(). Cannot use string slicing) ============================================================= Sample Input 1: hello o Sample Output 1: No Explanation 1: The word doesn’t start with ‘o’. ============================================================= Sample Input 2: lol l Sample Output 2: Yes Explanation 2: The word starts and ends with ‘l’. Also, ‘l’ doesn’t appear anywhere in the rest of the substring. ============================================================= Sample Input 3: astrazeneca a Sample Output 3: No Explanation 3: The word starts and ends with ‘a’ but ‘a’ is present in the substring “strazenec”.