User Tools

Site Tools


python:201908

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:201908 [2019/08/23 22:50] – aistispython:201908 [2019/08/23 22:52] (current) – aistis
Line 10: Line 10:
 ---- ----
  
-In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. +{{:python:pasted:20190823-225243.png}}
- +
-NOTE: String letters are case-sensitive. +
- +
-Input Format +
- +
-The first line of input contains the original string. The next line contains the substring. +
- +
-Constraints +
- +
- +
-Each character in the string is an ascii character. +
- +
-Output Format +
- +
-Output the integer number indicating the total number of occurrences of the substring in the original string. +
- +
-Sample Input +
- +
-ABCDCDC +
-CDC +
- +
-Sample Output +
- +
-2 +
- +
-Concept +
- +
-Some string processing examples, such as these, might be useful. +
-There are a couple of new concepts: +
-In Python, the length of a string is found by the function len(s), where +
- +
-is the string. +
-To traverse through the length of a string, use a for loop: +
- +
-for i in range(0, len(s)): +
-    print (s[i]) +
- +
-A range function is used to loop over some length: +
- +
-range (0, 5) +
- +
-Here, the range loops over +
-to . is excluded.+
  
  
 ---- ----
  
-Consider a list (list = []). You can perform the following commands: +{{:python:pasted:20190823-225214.png}}
- +
-    insert i e: Insert integer  +
- +
-at position +
-. +
-print: Print the list. +
-remove e: Delete the first occurrence of integer +
-. +
-append e: Insert integer +
- +
-    at the end of the list. +
-    sort: Sort the list. +
-    pop: Pop the last element from the list. +
-    reverse: Reverse the list. +
- +
-Initialize your list and read in the value of +
-followed by lines of commands where each command will be of the +
- +
-types listed above. Iterate through each command in order and perform the corresponding operation on your list. +
- +
-Input Format +
- +
-The first line contains an integer, +
-, denoting the number of commands. +
-Each line of the +
- +
-subsequent lines contains one of the commands described above. +
- +
-Constraints +
- +
-    The elements added to the list must be integers. +
- +
-Output Format +
- +
-For each command of type print, print the list on a new line. +
- +
-Sample Input 0 +
- +
-12 +
-insert 0 5 +
-insert 1 10 +
-insert 0 6 +
-print +
-remove 6 +
-append 9 +
-append 1 +
-sort +
-print +
-pop +
-reverse +
-print +
- +
-Sample Output 0 +
- +
-[6, 5, 10] +
-[1, 5, 9, 10] +
-[9, 5, 1]+
  
  
  
 ---- ----
-Task +{{:python:pasted:20190823-225132.png}}
-Given an integer, +
- +
-, perform the following conditional actions: +
- +
-    If  +
- +
-is odd, print Weird +
-If +
-is even and in the inclusive range of to +
-, print Not Weird +
-If +
-is even and in the inclusive range of to +
-, print Weird +
-If +
-is even and greater than +
- +
-    , print Not Weird +
- +
-Input Format +
- +
-A single line containing a positive integer, +
- +
-. +
- +
-Constraints +
- +
-Output Format +
- +
-Print Weird if the number is weird; otherwise, print Not Weird. +
- +
-Sample Input 0 +
- +
-3 +
- +
-Sample Output 0 +
- +
-Weird +
- +
-Explanation 0 +
- +
- +
-is odd and odd numbers are weird, so we print Weird. +
- +
-Sample Input 1 +
- +
-24 +
- +
-Sample Output 1 +
- +
-Not Weird +
- +
-Explanation 1 +
- +
- +
-and is even, so it isn't weird. Thus, we print Not Weird.+
python/201908.1566589841.txt.gz · Last modified: by aistis