PYTHON Programming short Questions:
1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs)
2. Write a function that takes as input a and b and returns the result of: ??ab
3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b
4. Write a function that takes as input names (list of strings) and returns the same list (do not make a new list) with only the elements that are all lowercase and are not numbers.
Question 1:
def function1(name,age):
print("\nMy name is %s and I am %d years old\n"
%(name,age))
name=input("\nEnter Name: ")
age=int(input("Enter Age: "))
function1(name,age)
Question 2:
def function2(a,b):
return(a+b+a+b)
a=input("\nEnter a: ")
b=input("\nEnter b: ")
print("\nResult: ",function2(a,b))
print("\n");
Question 3:
def function2(a,b):
if(a%b==0):
return(str(a)+str(b)+str(a)+str(b))
a=int(input("\nEnter a: "))
b=int(input("\nEnter b: "))
print("\nResult: ",function2(a,b))
print("\n");
Question 4:
def function4(names=[]):
return names
size=int(input("\nHow many names do you want in a list:
"))
names=[]
for i in range(0,size):
name=input("\nEnter Name: ")
if(name.isalpha()==True and
name.islower()==True):
names.append(name)
PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
In python,write a function nameSet(first, last) that takes a person's first and last names as input, and returns a tuple of three strings: the first string gives the union of all letters in the first and last names (no duplication though). The second string gives the intersection of letters in the first and last names, i.e. the common letters. If there are no common letters, then the second string is empty (''). The third string gives the symmetric difference between...
Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...
In python: ScoreFinder is a function that takes in two lists and a string. The first list is a list of strings (player names), the second list is a list of floats (player scores), and the string is a name (player to find). If the player to find exists in the list of player names, then print the name of that player along with their associated score (which is in the second list at the same index). If the player...
IN PYTHON 3) Number of Words Write a function numWords() which takes in a string can prints the number of words in the string. You can assume that words will only be separated with spaces, commas, and periods. "hello, world" -> 2 "this is cool" -> 3 4) Is Sorted Write a function isSorted() which takes in an list of integers and returns true if the numbers are sorted from smallest to largest.
Write a python function that takes a string as input, and returns a dictionary of frequencies of all the characters in the string. For example: freq("dabcabcdbbcd") would return {"d":3, "a":2, "b":4, "c":3}. Then write a driver to demonstrate your function.
Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...
Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...
Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...
Python: Using chr() and ord() write a function called en_crypt() that takes into input a string and returns a new encrypted version of the input string. Example: "atwOta@0202" should return "fy|TyfE5757", then write a function de_crypt() so that "fy|TyfE5757" returns "atwOta@0202"