
防老年痴呆语法练习
文章平均质量分 50
aladdin_sun
靡不有初,鲜克有终。
展开
-
语法练习:left2
Given a string, return a “rotated left 2” version where the first 2 chars are moved to the end. The string length will be at least 2.left2(‘Hello’) → ‘lloHe’left2(‘java’) → ‘vaja’left2(‘Hi’) → ‘Hi’Expected Run left2(‘Hello’) → ‘lloHe’ ‘lloHe’ OK left原创 2022-12-08 11:28:00 · 797 阅读 · 1 评论 -
语法练习:non_start
Given 2 strings, return their concatenation, except omit the first char of each. The strings will be at least length 1.non_start(‘Hello’, ‘There’) → ‘ellohere’non_start(‘java’, ‘code’) → ‘avaode’non_start(‘shotl’, ‘java’) → ‘hotlava’Expected Run non_s原创 2022-12-08 11:25:02 · 614 阅读 · 0 评论 -
语法练习:combo_string
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0).combo_string(‘Hello’, ‘hi’) → ‘hiH原创 2022-12-08 11:22:35 · 588 阅读 · 0 评论 -
语法练习:without_end
Given a string, return a version without the first and last char, so “Hello” yields “ell”. The string length will be at least 2.without_end(‘Hello’) → ‘ell’without_end(‘java’) → ‘av’without_end(‘coding’) → ‘odin’Expected Run without_end(‘Hello’) → ‘el原创 2022-12-08 11:18:13 · 442 阅读 · 0 评论 -
语法练习:first_half
Given a string of even length, return the first half. So the string “WooHoo” yields “Woo”.first_half(‘WooHoo’) → ‘Woo’first_half(‘HelloThere’) → ‘Hello’first_half(‘abcdef’) → ‘abc’Expected Run first_half(‘WooHoo’) → ‘Woo’ ‘Woo’ OK first_half(‘HelloTh原创 2022-12-08 11:14:15 · 281 阅读 · 0 评论 -
语法练习:first_two
Given a string, return the string made of its first two chars, so the String “Hello” yields “He”. If the string is shorter than length 2, return whatever there is, so “X” yields “X”, and the empty string “” yields the empty string “”.first_two(‘Hello’) → ‘原创 2022-12-08 11:08:27 · 367 阅读 · 0 评论 -
语法练习:extra_end
Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2.extra_end(‘Hello’) → ‘lololo’extra_end(‘ab’) → ‘ababab’extra_end(‘Hi’) → ‘HiHiHi’Expected Run extra_end(‘Hello’) → ‘l原创 2022-12-08 11:02:58 · 283 阅读 · 0 评论 -
语法练习:make_out_word
Given an “out” string length 4, such as “”, and a word, return a new string where the word is in the middle of the out string, e.g. “”.make_out_word(‘’, ‘Yay’) → ‘’make_out_word(‘’, ‘WooHoo’) → ‘’make_out_word(‘[[]]’, ‘word’) → ‘[[word]原创 2022-12-08 10:56:14 · 233 阅读 · 0 评论 -
语法练习:make_tags
The web is built with HTML strings like “Yay” which draws Yay as italic text. In this example, the “i” tag makes and which surround the word “Yay”. Given tag and word strings, create the HTML string with tags around the word, e.g. “Yay”.make_tags(‘i’, ‘Y原创 2022-12-08 10:53:30 · 241 阅读 · 0 评论 -
语法练习:make_abba
Given two strings, a and b, return the result of putting them together in the order abba, e.g. “Hi” and “Bye” returns “HiByeByeHi”.make_abba(‘Hi’, ‘Bye’) → ‘HiByeByeHi’make_abba(‘Yo’, ‘Alice’) → ‘YoAliceAliceYo’make_abba(‘What’, ‘Up’) → ‘WhatUpUpWhat’Ex原创 2022-12-08 10:47:28 · 215 阅读 · 0 评论 -
语法练习:hello_name
Given a string name, e.g. “Bob”, return a greeting of the form “Hello Bob!”.hello_name(‘Bob’) → ‘Hello Bob!’hello_name(‘Alice’) → ‘Hello Alice!’hello_name(‘X’) → ‘Hello X!’Expected Run hello_name(‘Bob’) → ‘Hello Bob!’ ‘Hello Bob!’ OK hello_name(‘Alic原创 2022-12-08 10:45:03 · 246 阅读 · 0 评论 -
语法练习:string_match
Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So “xxcaazz” and “xxbaaz” yields 3, since the “xx”, “aa”, and “az” substrings appear in the same place in both strings.string_match(‘xxcaazz’, ‘xxb原创 2022-12-07 11:26:29 · 421 阅读 · 0 评论 -
语法练习:array123
Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere.array123([1, 1, 2, 3, 1]) → Truearray123([1, 1, 2, 4, 1]) → Falsearray123([1, 1, 2, 1, 2, 3]) → TrueExpected Run array123([1, 1, 2, 3, 1]) → True Tru原创 2022-12-07 11:09:35 · 505 阅读 · 0 评论 -
语法练习:array_front9
Given an array of ints, return True if one of the first 4 elements in the array is a 9. The array length may be less than 4.array_front9([1, 2, 9, 3, 4]) → Truearray_front9([1, 2, 3, 4, 9]) → Falsearray_front9([1, 2, 3, 4, 5]) → FalseExpected Run arra原创 2022-12-07 11:03:32 · 415 阅读 · 0 评论 -
语法练习:array_count9
Given an array of ints, return the number of 9’s in the array.array_count9([1, 2, 9]) → 1array_count9([1, 9, 9]) → 2array_count9([1, 9, 9, 3, 9]) → 3Expected Run array_count9([1, 2, 9]) → 1 1 OK array_count9([1, 9, 9]) → 2 2 OK array_count9([1, 9, 9原创 2022-12-07 10:47:14 · 310 阅读 · 0 评论 -
语法练习:last2
Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so “hixxxhi” yields 1 (we won’t count the end substring).last2(‘hixxhi’) → 1last2(‘xaxxaxaxx’) → 1last2(‘a原创 2022-12-07 10:43:57 · 433 阅读 · 0 评论 -
语法练习:string_splosion
Given a non-empty string like “Code” return a string like “CCoCodCode”.string_splosion(‘Code’) → ‘CCoCodCode’string_splosion(‘abc’) → ‘aababc’string_splosion(‘ab’) → ‘aab’Expected Run string_splosion(‘Code’) → ‘CCoCodCode’ ‘CCoCodCode’ OK string_splo原创 2022-12-07 10:34:51 · 207 阅读 · 0 评论 -
语法练习:string_bits
Given a string, return a new string made of every other char starting with the first, so “Hello” yields “Hlo”.string_bits(‘Hello’) → ‘Hlo’string_bits(‘Hi’) → ‘H’string_bits(‘Heeololeo’) → ‘Hello’Expected Run string_bits(‘Hello’) → ‘Hlo’ ‘Hlo’ OK stri原创 2022-12-07 10:29:42 · 259 阅读 · 0 评论 -
语法练习:front_times
Given a string and a non-negative int n, we’ll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front;front_times(‘Chocolate’, 2) → ‘ChoCho’front_times(‘Chocolate’, 3)原创 2022-12-07 10:21:35 · 215 阅读 · 0 评论 -
语法练习:string_times
Given a string and a non-negative int n, return a larger string that is n copies of the original string.string_times(‘Hi’, 2) → ‘HiHi’string_times(‘Hi’, 3) → ‘HiHiHi’string_times(‘Hi’, 1) → ‘Hi’Expected Run string_times(‘Hi’, 2) → ‘HiHi’ ‘HiHi’ OK st原创 2022-12-07 10:15:39 · 187 阅读 · 0 评论 -
语法练习:front3
Given a string, we’ll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front.front3(‘Java’) → ‘JavJavJav’front3(‘Chocolate’) → ‘ChoChoC原创 2022-12-06 17:10:55 · 270 阅读 · 0 评论 -
语法练习:front_back
Given a string, return a new string where the first and last chars have been exchanged.front_back(‘code’) → ‘eodc’front_back(‘a’) → ‘a’front_back(‘ab’) → ‘ba’Expected Run front_back(‘code’) → ‘eodc’ ‘eodc’ OK front_back(‘a’) → ‘a’ ‘a’ OK front_back(原创 2022-12-06 17:05:57 · 573 阅读 · 0 评论 -
语法练习:missing_char
Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0…len(str)-1 inclusive).missing_char(‘kitten’, 1) → ‘k原创 2022-12-06 16:59:19 · 273 阅读 · 0 评论 -
语法练习:not_string
Given a string, return a new string where "not " has been added to the front. However, if the string already begins with “not”, return the string unchanged.not_string(‘candy’) → ‘not candy’not_string(‘x’) → ‘not x’not_string(‘not bad’) → ‘not bad’Expect原创 2022-12-06 16:53:04 · 390 阅读 · 0 评论 -
语法练习:pos_neg
Given 2 int values, return True if one is negative and one is positive. Except if the parameter “negative” is True, then return True only if both are negative.pos_neg(1, -1, False) → Truepos_neg(-1, 1, False) → Truepos_neg(-4, -5, True) → TrueExpected R原创 2022-12-06 16:38:41 · 413 阅读 · 0 评论 -
语法练习:near_hundred
Given an int n, return True if it is within 10 of 100 or 200. Note: abs(num) computes the absolute value of a number.near_hundred(93) → Truenear_hundred(90) → Truenear_hundred(89) → FalseExpected Run near_hundred(93) → True True OK near_hundred(90) →原创 2022-12-06 16:30:01 · 344 阅读 · 0 评论 -
语法练习:makes10
Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10.makes10(9, 10) → Truemakes10(9, 9) → Falsemakes10(1, 9) → TrueExpected Run makes10(9, 10) → True True OK makes10(9, 9) → False False OK makes10(1, 9) → True True OK makes原创 2022-12-06 16:20:31 · 192 阅读 · 0 评论 -
语法练习:parrot_trouble
We have a loud talking parrot. The “hour” parameter is the current hour time in the range 0…23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble.parrot_trouble(True, 6) → Trueparrot_trouble(原创 2022-12-06 15:56:15 · 160 阅读 · 0 评论 -
语法练习:diff21
Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.diff21(19) → 2diff21(10) → 11diff21(21) → 0Expected Run diff21(19) → 2 2 OK diff21(10) → 11 11 OK diff21(21) → 0 0 OK diff原创 2022-12-06 09:33:50 · 130 阅读 · 0 评论 -
语法练习:sum_double
Given two int values, return their sum. Unless the two values are the same, then return double their sum.sum_double(1, 2) → 3sum_double(3, 2) → 5sum_double(2, 2) → 8Expected Run sum_double(1, 2) → 3 3 OK sum_double(3, 2) → 5 5 OK sum_double(2, 2) →原创 2022-12-06 09:30:44 · 176 阅读 · 0 评论 -
语法练习:monkey_trouble
We have two monkeys, a and b, and the parameters a_smile and b_smile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return True if we are in trouble.monkey_trouble(True, True) → Truemonkey_trouble原创 2022-12-06 09:27:21 · 126 阅读 · 0 评论 -
语法练习:sleep_in
语法练习原创 2022-12-06 09:23:00 · 299 阅读 · 0 评论