Question

write a code in python Write the following functions below based on their comments. Note Pass...

write a code in python

Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries.

#!/usr/bin/python3

#(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are less than 6. If they are, the function will return true if they aren’t, the function will return false.

def all_less_than_6(x):

    pass

# This function will ask the user for a string. It will check to see if the inputted string contains only digits and all the digits are less than 6. If they aren’t ask the input to try again and keep asking until they get correct

def get_input():

    pass

# (1 Mark) This function will take in a num between 0 and 9 it should return

# C if x is 0

# E if x is 1

# L if x is 2

# R if x is 3

# N if x is 4

# O if x is 5

# Y if x is 6

# A if x is 7

# D if x is 8

# W if x is 9

def conv(x):

pass

# This function will do some weird math on a string of digits. It should return a string that numi = input_stri + input_stri+1,if i = len(input_str)-1 then numi = input_stri + input_str0. If numi is equal to 10 then set it to be 0. Example 1243 will be 3674 because 1+2 = 3, 2+4 = 6, 4+3 = 7 and 3+1 = 4. Another example 55 will be 00 because 5+5 = 10 and 5+5 = 10

def weirdness(input_str):

    pass

   

   

# This function will print out a message using a string of digits and the conv function.   

def more_weirdness(x):

#This is where you make it all work

if __name__ == "__main__" :

    print(“HELLO WORLD”)

When your script is done it should be able to recreate the following output

Enter in a string of digits where each digit is less than 6

>43326

Try again! Enter in a string of digits where each digit is less than 6

>1423H34

Try again! Enter in a string of digits where each digit is less than 6

>1243

3674

RYAN

Add your scripts output for the following input 4422102505543

Homework Answers

Answer #1

In case of any query do comment. Thanks

Code:

#!/usr/bin/python3
#(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are less than 6. If they are, the function will return true if they aren’t, the function will return false.

def all_less_than_6(x):
    for digit in x:
        digit = int(digit)
        if digit >=6:
            return False
    return True

#(2 Marks) This function will ask the user for a string. It will check to see if the inputted string contains only digits and all the digits are less than 6. If they aren’t ask the input to try again and keep asking until they get correct

def get_input():
    while True:
        stringOfDigits = input("Enter in a string of digits where each digit is less than 6\n")
        if stringOfDigits.isdigit() and all_less_than_6(stringOfDigits):
            return stringOfDigits
        else:
            print("Try again!",end=" ")
            
        

# (1 Mark) This function will take in a num between 0 and 9 it should return

# C if x is 0
# E if x is 1
# L if x is 2
# R if x is 3
# N if x is 4
# O if x is 5
# Y if x is 6
# A if x is 7
# D if x is 8
# W if x is 9

def conv(x):
    #create a list of return values and it's index would be the number and item would be the return value
    # as we put C at 0 index, E at index 1 , L at index 2 and ..... W on index 9 and simply return the value at the given index
    convertList = ['C','E','L','R','N','O','Y','A','D','W']
    return convertList[x]

#(4 Marks) This function will do some weird math on a string of digits. It should return a string that numi = input_stri + input_stri+1,if i = len(input_str)-1 then numi = input_stri + input_str0. If numi is equal to 10 then set it to be 0. 
#Example 1243 will be 3674 because 1+2 = 3, 2+4 = 6, 4+3 = 7 and 3+1 = 4. Another example 55 will be 00 because 5+5 = 10 and 5+5 = 10

def weirdness(input_str):
    #store the length of the input_str 
    length = len(input_str)
    #initialize return value with empty string
    sumOfDigits =""
    for i in range(length):
        #take out the first digit
        firstDigit = int(input_str[i])
        #check for length and according take out next digit or first Digit
        if i == length -1:
            secondDigit = int (input_str[0])
        else:
            secondDigit = int (input_str[i+1])
        #do a local sum
        localSum = firstDigit + secondDigit
        #if localSum is 10 then make it 0
        if localSum == 10:
            localSum =0
        #add localSum to the return value
        sumOfDigits += str(localSum)
    
    return sumOfDigits
    

#(1 Marks) This function will print out a message using a string of digits and the conv function.   

def more_weirdness(x):
    weirdString = weirdness(x)
    convResult =""
    for digit in weirdString:
        convResult += conv(int(digit))
    print(weirdString)
    print(convResult)    
#This is where you make it all work


if __name__ == "__main__" :
    digits = get_input()
    more_weirdness(digits)
   
   

========Screen shot of the code for indentation========

output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in pyhton: This function will ask the user for a string. It will check to see...
in pyhton: This function will ask the user for a string. It will check to see if the inputted string contains only digits and all the digits are less than 6. If they aren’t ask the input to try again and keep asking until they get correct def get_input():
In python comment the following code line by line as to what each line does def...
In python comment the following code line by line as to what each line does def f(x): return 6*x**5-5*x**4-4*x**3+3*x**2 #here we define a polynomial def df(x): return 30*x**4-20*x**3-12*x**2+6*x #here we define a polynomial that takes the derivative of the above function f(x) def dx(f, x): return abs(0 - f(x)) def newtons_method(f, df, x0, e): delta = dx(f, x0) while delta > e: x0 = x0 - f(x0)/df(x0) delta = dx(f, x0) print('Root is at:', x0) print('f(x) at root is: ',...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
With the code given write python code that prints the probability of getting a flush when...
With the code given write python code that prints the probability of getting a flush when you run 10**5 trails. this is what i have so far but it says that isFlush is not defined. why? # Print out probability that a 5-card hand has all the same suit #seed(0) num_trials = 10**5 trials = [dealHand for k in range(num_trials)] # 5 card hand prob = sum([l for h in trials if isFlush(h)])/num_trials # sum the list of numbers that...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking option entered by the user print("Enter 0 to 5 for following options: ") print("0-> Issue new ticket number.") print("1-> Assign first ticket in queue to counter 1.") print("2-> Assign first ticket in queue to counter 2.") print("3-> Assign first ticket in queue to counter 3.") print("4-> Assign first ticket in queue to counter 4.") print("5-> Quit Program.") tickets = [] #Declaring list to store...
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
Complete in python3 , I know how to start a countdown but im having trouble displaying...
Complete in python3 , I know how to start a countdown but im having trouble displaying the word instead of zero Countdown Write a function as follows. * function name: countdown * parameters: start (int) whoopee_word (string) * returns: N/A * operation: Count down from start to 1. Instead of 0, print the whoopee_word. BUT: - If start is less than 1 or greater than 20, print "start is out of range" and exit the function - If start is...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT