Question

In: Computer Science

In Python, accept shoter names and pad them with X’s to fill out the 3 characters...

In Python, accept shoter names and pad them with X’s to fill out the 3 characters needed.

So for example

>>> print(user_name("Bo", "Li"))

BoXLiX

>>> )

Solutions

Expert Solution

#define function
def user_name(str1, str2):
    #checks if length of str1 is less than 3 
    if(len(str1) < 3):
        #if length is less than 3 then append X until length of str1 becomes 3
        for i in range(len(str1),3):
            str1 = str1 + 'X'
    
    #checks if length of str2 is less than 3 
    if(len(str2)<3):
        #if length is less than 3 then append X until length of str2 becomes 3
        for i in range(len(str2),3):
            str2 = str2 + 'X'
    
    #return both string
    return str1+str2

#call user_name function and print the result    
print(user_name("Bo","Li"))


Related Solutions

Python 3 A simple way to encrypt a file is to change all characters following a...
Python 3 A simple way to encrypt a file is to change all characters following a certain encoding rule. In this question, you need to move all letters to next letter. e.g. 'a'->'b', 'b'->'c', ..., 'z'->'a', 'A'->'B', 'B'->'C', ..., 'Z'->'A'. For all digits, you need to also move them to the next number. e.g. '0'->'1', '1'->'2', ..., '9'->'0'. All the other symbols should not be changed. Write a function encrypt with the following requirements: the function takes a string argument,...
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line...
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line using nested loops. Here is what you need to know: 1- Copy this and don't change the inputs in the provided code: # Get the size and drawing character from the user size = input('Please enter the size: ') # Validate the input, exit if bad if size.isdigit(): size = int(size) else: print("Exiting, you didn't enter a number:", size) exit(1) # Input the drawing...
1.) (Be Sure to fill out full 6 steps number them) Q: A college admissions officer...
1.) (Be Sure to fill out full 6 steps number them) Q: A college admissions officer for the school’s online undergraduate program wants to estimate the mean age of its graduating students. The administrator took a random sample of 40 from which the mean was 24 years and the standard deviation was 1.7 years. If the mean age of online undergraduate students was 23 years of age, what is the probability that the sample of 40 would have produced a...
Using the terms "none," "low," "high," fill out Columns 2 and 3 of the Table III...
Using the terms "none," "low," "high," fill out Columns 2 and 3 of the Table III below and write notes in the last column Table III Possible genotypes Risk of sickle cell anemia Likelihood of surviving malaria Notes on risks of sickle cell anemia and malaria SS Homozygous dominant for the wild type beta-globin allele Ss Heterozygous for the wild type beta-globin allele "Sickle cell trait"= carrier ss Homozygous recessive for the wild type beta-globin allele will develop sickle cell...
Please answer questions 1-3 and fill out both charts columns ( Different and % Change) as...
Please answer questions 1-3 and fill out both charts columns ( Different and % Change) as well as the (percentage). I can't award credit if all questions and charts are not completed. Balance sheet data for Silver Corporation are presented here. Using Comparative Analysis SILVERT CORPORATION Balance Sheet December 31 Different % Change 2012 2011 ASSET Cash $                28,000 $             20,000 Receivable (net) 70,000 62,000 Other current assets 90,000 73,000 Long-term investment 62,000 60,000 Plant and equipment (net) 510,000 470,000...
Snow White recieves a basket of 11 apples, out of which 3 of them are poisoned....
Snow White recieves a basket of 11 apples, out of which 3 of them are poisoned. She decides to eat 5 of them. Let X1denote the number of unpoisoned apples that she eats. Check all that are true about X1. A. The trials are independent B. The trials have two outcomes C. The trials have the same probability of success. D. There are a set number of trials E. We can model X1 with a collection of trials Snow White...
ANSWER IT IN PYTHON KINDLY ANSWER PROBLEM 2 AND 3. LEAVE PROBLEM 1 OUT. # General...
ANSWER IT IN PYTHON KINDLY ANSWER PROBLEM 2 AND 3. LEAVE PROBLEM 1 OUT. # General instructions: ''' I suggest you to read the problem statements first and think how you can solve the problem. Think about your own way. Then check out the hints written as comments. After each hint there should be an empty line. Write your line of code in there to satisfy the comment (you may have to store the the value in a variable but...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT