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():
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 =...
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...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
This question is broken into 3 parts, each of which builds on the functions developed in...
This question is broken into 3 parts, each of which builds on the functions developed in the previous part. Note that you can (and should) still answer parts (b) and (c) even if you cannot answer the preceding parts - just assume that the functions work as they should, and continue. Please explain the code as well Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT