Given a string s with even length, write an expression to return the first half of the string. (in python3)
answer)
s=input("Enter a string s with even length: ")
length=int(len(s)/2)
if(len(s)%2==0):
print(s[0:length])
else:
print("String length is not even")
output:
Given a string s with even length, write an expression to return the first half of...
Write a context-free grammar for the language where all strings are of even length and the first half of the string is all 0’s, but it must be an odd number of 0’s
Python3 : Write the function longestRun(s, chars) that takes a possibly-empty string s and a second possibly-empty string of chars. We will say that a character is "good" if it is in the chars string (case insensitively, so "A" and "a" would match). The function should return the length of the longest consecutive run of good characters in the given string s. For example, consider: longestRun("abbcazBbcababb","bz"). This returns 3 (look for "zBb"). Restrictions: for loop, slicing cannot be used, if...
Add or Subtract. Write a function (add-sub-string s). The function consumes a Str of even length, where every even- numbered character is either "+" or "-", and odd-valued characters are numeric The function should add up all the digits that follow a "+", and subtract all the digits that follow a "-". For example, (add-sub-string "+3+4-5") => 2 (add-sub-string "-5+3+4-6-6") - 10 => The interface file contains the function char->nat that converts a numeric Char to the corresponding numeric value....
Write a function that can return the length of a string in C language. Please leave comments to explain the code and verify that it runs properly... Example: Input String: China The length of the string is 5. #include <stdio.h> int length(char * p) { /write your code here } main(){ int len; char str[20]; printf("Input string:"); scanf("%s", str); len = length(str); printf("The length of string is %d. ", len); getchar(); ...
Given a String variable address, write a String expression consisting of the string "http://" concatenated with the variable's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com". In python please
Write a program that prompts a user for an input string of length at least two and prints the string with the first half in upper case and the second half in lower case. If the length of the string is odd, the "second half" should be one character longer than the "first half". Show Hint
In Python3 write a function, given a string, compute recursively the number of times lowercase "hi" appears in the string,.
plz answers these short Qs in python language Q1-Given the String variable address, write an expression that returns the position of the first occurrence of the String "Avenue" in address. Q2-Write a sequence of statements that finds the first comma in the string associated with the variable line, and associates the variable clause the portion of line up to, but not including the comma. Q3-Assume that sentence is a variable that has been associated with a string consisting of words...
Java Exercise 19. Given a string, if the first or last chars are 'x', return the string without those 'x' chars, and otherwise return the string unchanged.