Question

In: Computer Science

In Python, write a function one_bit_NOT that takes one argument, a character that is either '0'...

In Python, write a function one_bit_NOT that takes one argument, a character that is either '0' or '1'. It should perform the NOT operation and return a string with a single character as the result. I.e., if the character argument is "0", it returns a "1"'. If the character argument is "1", it returns a "0".

Solutions

Expert Solution

Source Code:

def one_bit_NOT(ch):
temp=int(ch) # converting char to int i.e, here we get integer
temp=not(temp) # applying NOT operation i.e, here we get boolean value
temp=int(temp) # converting boolean to int i.e, here we get integer
temp=str(temp) # converting int to char i.e, here we get charcter

return temp # returning character

ch='0'
print(one_bit_NOT(ch)) # it prints '1'
ch='1'
print(one_bit_NOT(ch)) # it prints '0'


Related Solutions

In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and...
In C: Write a function definition called PhoneType that takes one character argument/parameter called phone and returns a double. When the variable argument phone contains the character a or A print the word Apple and return 1099.99 When phone contains anything else return a 0.0
Write a python function image compress() that takes one argument called filename, which is the name...
Write a python function image compress() that takes one argument called filename, which is the name of a file that contains a N × N (N-pixel by N-pixel) “grayscale bitmap image”. A “grayscale bitmap image” is an image of the following form where every pixel contains a grayscale color value between 0 − 255 (inclusive). Colour value 0 means that pixel should appear completely black and color value 255means completely white. Any other value in between stands for different shades...
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence to an element at a higher index. Assumptions and restrictions: The function must return a number. If there is no increasing pair in the sequence, the function should return 0. This may happen for example if the sequence is decreasing, or if it contains fewer than 2 elements. You can assume that the argument...
Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
In the same module/file, write a function processAnimals that takes one argument, the name of an...
In the same module/file, write a function processAnimals that takes one argument, the name of an input file.   The function returns the list of animals created or an empty list if the file didn't contain any lines. The input file contains zero or more lines with the format: species, language, age where species is a string representing an animal's species, language is a string representing an animal's language, and age is an integer representing an animal's age. The items on...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character argument/ parameter called "phone" and returns a double. When the variable argument phone contains the caracter a or A, print the word Apple and return 1099.99. When phone contains the caracter s or S print the word Samsung and return 999.99. When phone contains anything else, return 0.0.
Write a function called swapElements to swap two elements in a character array. This function takes...
Write a function called swapElements to swap two elements in a character array. This function takes two parameters, a character array and input file. The function should read two numbers from a file and it swap the elements stored in the indices read. please code in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT