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 consists of only the digits 0 and 1 (if not, return “not a binary string”)
• Verifies that it has length 8 (if not, return “wrong length”)
• It returns the eight-bit binary string that results from flipping bits: 0 becomes 1 and 1 becomes 0 Name this function flipBits(myString).
For example, >>>flipBits(“123”) should return the string “not a binary string”.
As another example, >>>flipBits(“1100”) should return the string “wrong length”.
As a final example, >>>flipBits(“11001010”) should return the string “00110101”
4. Write a function that takes, as an argument, two four-bit binary strings, string1 and string2, and does the following, in this order: • Verifies that both strings consist of only the digits 0 and 1 (if not, return “not binary strings”)
• Verifies that both strings have length 4 (if not, return “wrong length”)
• It returns the result of string1 XOR string2 Name this function xor(string1, string2).
For example, >>>xor(“1”, “abc”) should return the string “not binary strings”.
As another example, >>>xor(“1100”, “1”) should return the string “wrong length”.
As a final example, >>>xor(“1100”, “1010”) should return the string “0110”
3)
CODE
def flipBits(myString):
if len(myString) != 8:
return "Wrong length"
for bit in myString:
if bit != '0' and bit != '1':
return "not a binary string"
flipped = ""
for bit in myString:
if bit == "0":
flipped += "1"
else:
flipped += "0"
return flipped
print(flipBits("123"))
print(flipBits("1100"))
print(flipBits("11001010"))
NOTE: As per HOMEWORKLIB POLICY I am allowed to answer specific number of questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit...
(PYTHON please) Write a function that takes, as an argument, a positive integer n, and creates a file, named fourBits.txt, containing n randomly generated four-bit binary strings, each on its own line. Examples of four-bit binary strings include “1111” and “0011”. Name this function fourBitStrings(n).
PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].
Define a function called AddEvenPosDigs(string), which takes a string (with symbols and characters) as an argument, and returns an integer. This function should add the digits of a string that are in an even position. If there are no digits, the function should return -1. As an example, the following code fragment: string = "a12b056jk"; result=AddEvenPosDigs(string); print(result) should produce the output: 8
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...
Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....
Using C, Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you should not return a string that you created inside the reverse function! For example: Test char str[]-"hello" printf("%s", reverse (str)); Result olleh
write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...
Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.
Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as 5155551212) as input, convert into a more readable string with parentheses and dashes like (515)555-1212 and display it. If the input string contains more than or less than ten characters, display an error message. Note: Steps of phoneNumberFormat function can be given as follows: def phoneNumberFormat (phoneNum): 1. Let l be the length of the phoneNum 2. If 1 does not equal 10 then,...