def longest(string1, string2):
"""Return the longest string from the two arguments,
if the strings are the same length, return the first string
def count_over(thelist, n):
"""Return the number of integers in thelist that are
greater than the integer n
def bmi(height, weight):
"""Given a height (m) and weight (kg) (numbers) compute the
Body Mass Index for an individual.
Return the BMI as a float========================================================================
def longest(str1, str2):
if len(str1) > len(str2):
return str1
else:
return str2
def count_over(nums, n):
ctr = 0
for x in nums:
if x > n:
ctr = ctr + 1
return ctr
def bmi(height, weight):
return(float(weight/(height * height)))
print(longest("Samuel", "Sam")) #prints Samuel
print(count_over([1,2,3,4,5,6,7,8,9], 4)) #prints 5
print(bmi(1.5, 80)) #prints 35.5555
===================================================================
Please upvote the answer if you liked it :D. Also, do leave a comment if you have any queries
PYTHON The function longest that returns the longest of two strings. The function count_over that takes...
containsSubSequence takes two Strings as input and returns a boolean: Returns true if the first input string contains all the characters of the second input string, in order, but not necessarily consecutively. > HW2.containsSubSequence("abracadabra", "abcd") true > HW2.containsSubSequence("abracadabra", "abdc") false you must not use either break or continue in your code. You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method I write something...
In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit positive integer n or a string consisting of 12 digits, and calculates the 13th digit (the check digit) for a 13-digit ISBN. Name this function calculateCheckDigit(n). For example, >>>calculateCheckDigit(452678904653) should return 5. As an additional example, >>>calculateCheckDigit(546654945486) should return 8. 3. Write a function that takes, as an argument, an eight-bit binary string and does the following, in this order: • Verifies that it...
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string of their sum. *Simply converting strings to numbers and adding them together isn’t acceptable.* The program must be able to handle large decimals. Be sure to touch on these when solving for the solution: Pad the right side Pad the left side Make sure string is same length by putting 0’s where it was missing (be careful w/ decimal points) Make sure to remove...
/////////////////////////////////////////////////////////////////////////////////// //This program // 1. asks the user her/his weight and height // 2. then calculates the user's body-mass-index (BMI) // 3. and then prints an appropriate message based on the user's BMI /////////////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; void printWelcome(); // ask the weight (in pounds) and height (in inches) of the user and store the values in formal // parameters weight and height, respectively void getWeightAndHeight(float& weight, float& height); // calculate and return the BMI (Body-Mass-Index) based on...
Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...
Write a function rm_multiple() that takes two parameters as input (a list of strings, and a list of strings to remove from the list) and returns a new list with the items removed. # Define function in this cell def rm_multiple(strings,remove_list): l = [10,20,40,50] #use to delete an element in the list for string in strings: strings= l if string not in remove_list: lst.append(string) # Edit the code here to call your function in this cell items = [10,20,40,50] to_remove...
With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...
Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep...
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...
Guessing one password: write a function called guess that takes a string (a guessed password) as an argument and prints out matching information if its encrypted string matches any of the strings in the encrypted password file. When you write the function, you may hardcode the name of the password file. Here is an example run: >>> guess("blue") Found match: blue Line number: 1 Encrypted value: 16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548 You will want to use the encrypt function presented in class: import hashlib...