RAW CODE
def highest_value_word(word1,word2,ordinal_position=1):
if word1 == word2:
return 0
elif word1 == '':
return ordinal_position
elif word2 == '':
return ordinal_position
elif word1[0] == word2[0]:
ordinal_position += 1
found = highest_value_word(word1[1:],word2[1:],ordinal_position)
if found:
return found
print(ordinal_position)
elif word1[0] > word2[0]:
return ordinal_position * -1
else:
return ordinal_position
if __name__ == '__main__':
word_list = ["Kiwi","Weka"]
print(highest_value_word(word_list[0],word_list[1]))
word_list = ["Ruru","Ruru"]
print(highest_value_word(word_list[0],word_list[1]))
word_list = ["Kaka","Kakapo"]
print(highest_value_word(word_list[0],word_list[1]))
word_list = ["Huia","Hoiho"]
print(highest_value_word(word_list[0],word_list[1]))
SCREENSHOT (CODE WITH OUTPUT) #### ALONG WITH COMMENTS
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####
Words like first, second and third are referred to as ordinal numbers. In this exercise, you will write a function that takes an integer as its only parameter and returns a string containing the appropriate English ordinal number as its only result. Your function must handle the integers between 1 and 12 (inclusive). It should return an empty string if the function is called with an argument outside of this range. Include a main program that demonstrates your function by displaying each integer from 1 to 12 and its ordinal number. Your main program should only run when your file has not been imported into another program.
Python
Python The Python "<" and ">" comparison operators can be used to compare which string variable...
Python 3: Write a function called every_other_character() that takes in a string and returns a new string with every other character removed. That is, the new string will include the first, third, fifth, etc. letters of the given string. Must use a while or for loop in the solution.
python rephactor 1. Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported. 2. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal.
2. Overload a function "display" so that (a) if display is called with a string, it prints the string 5 times and then returns the length of the string (b) if it is called with an integer, n, it prints n, 2n, 3n and has no return value (c) if it is called with a character, it prints the character on the first line, 2 of the character on the 2nd line, 3 of it on the 3rd line and...
1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...
Python Language Problems 1. isdigit() A. Returns True if this string is just a digit. B. Returns True if this string contains only number characters. C. Return True if this string has at least one number character. D. is not a valid function. 2. Pick the most accurate interpretation for the if construct: if letter in words: print("Got it") A. If the character letter existed in the string words, it prints "Got it". B. It traverse through the string words,...
PYTHON 1- Write a function that receives a string value as a parameter, converts its first character to uppercase and returns the first character. 2- Test your function by writing a main, which calls your function and prints its return value. 3- Save your program in a file called firstChar.py and use the following link to submit your file.
Python 3.6 I JUST NEED HELP WITH PROBLEM 2 (CONTINUATION OF PROBLEM 1)!!! THIS IS MY WORK FOR PROBLEM 1 (I NEED HELP WITH PROBLEM 2): Python 3.6 Problem 1 This problem provides practice using a while Irue loop Write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the second word begins with a specified letter. The function twoWords takes two parameters: 1. an integer, length,...
Python Programming: An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded as letter T to make all card ranks to be single letters) • the second character is from "cdhs" and represents the suit (clubs, diamonds, hearts and spades respectively). For example, "Jd" would be the jack of diamonds, and "4s" would be...
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...
PYTHON 3.6 (Short and Simple Codes Please) Write a recursive function, reverse, that accepts a parameter containing a string value and returns the original string in reverse. For example, calling reverse('goodbye') would return 'eybdoog'. Reversing a string involves: No action if the string is empty or only has 1 character Concatenating the last character with the result of reversing the string consisting of the second through next-to-last character, followed by the first character