Question

In: Computer Science

In Python The following code is intentionally done in poor style but runs as intended. def...

In Python

The following code is intentionally done in poor style but runs as intended.
def main():

c = 10

print("Welcome to Roderick's Chikkin and Gravy")

e = False

while not e:

x = input("Would you like some chikkin?")

if x == "Y" or x == "y":

c = f(c)

else:

e = True

if c == 0:

e = True

print("I hope you enjoyed your chikkin!")

def f(c):

if c > 0:

print("Got you some chikkin! Enjoy")

return c-1

else:

print("No chikkin left. Sorry")

return 0

main()

1.Fix it *then* add the functions mentioned (Including totally deleting these comments at the top and replacing them with)
What should be here as well as changing the repl name!?

2.Fix the style of this program so it is clear what it is doing.

3.Add to the code so that, if you want chikkin, you are asked if you want gravy. If you say yes, the (only) output for that order should be, "You get some chikkin and gravy then!" If not, it should give the same output as the original program. In both cases, it will then ask you again if you want any chikkin.

4.Add to the code so that, if you want chikkin, you are asked if you want gravy. If you say yes, the (only) output for that order should be, "You get some chikkin and gravy then!" If not, it should give the same output as the original program. In both cases, it will then ask you again if you want any chikkin. (You can do whatever you would like to get this to happen - adding a new function is not required but don't delete the old function entirely). Assume you have infinite gravy so no tracking how much gravy there is.

5.Write a simple function named startingChikkin() that has no parameters and just asks the user for how much chikkin we start with. If the user types a positive integer, then return that value. If not, prompt again repeatedly until they enter a positive integer which you then return (see earlier sections on input validation) - the loop should be inside of your function. Call startingChikkin() at the start of the main() program and store the value returned into whatever you called your variable for tracking the number of chikkins left.

Solutions

Expert Solution

Here is the code:

def main():
    def startingChikkin():
        while(True):
            ans = int(input('How much chikkin we start with?: '))
            if(ans > 0):
                return(ans)
            
    def f(c):
        if c > 0:
            print("Got you some chikkin! Enjoy")
            return c-1
        else:
            print("No chikkin left. Sorry")
        return 0
            
    c = 10    # number of chicken
    print("Welcome to Roderick's Chikkin and Gravy")
    e = False
    while not e:
        x = input("Would you like some chikkin?: ")
        if x == "Y" or x == "y":
            num_chicken = startingChikkin()
            y = input("Would you like some gravy?: ")
            if y == "Y" or y == "y":
                print("You get some chikkin and gravy then!")
            c = f(num_chicken)
        else:
            e = True
        if c == 0:
            e = True
            print("I hope you enjoyed your chikkin!")
            
# calling the function
main()

Here is the output:


Related Solutions

PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def take_e(n, gen):     return [elem for (i, elem) in enumerate(gen) if i < n] def take_zc(n, gen):     return [elem for (i, elem) in zip(count(), gen) if i < n] FIBONACCI UNBOUNDED: def fibonacci_unbounded():     """     Unbounded Fibonacci numbers generator     """     (a, b) = (0, 1)     while True:         # return a         yield a         (a, b) = (b, a + b) SUPPOSED TO RUN THIS TO ASSIST WITH...
Python code def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2...
Python code def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user defined by having the most interests in common. Return a tuple: (most_similar_user, num_interests_in_common) """ return ("", 0)    def recommendations(user, interests): """ Find the user who shares the most interests with the specified user. Recommend to user any interests that...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer Protocol (FTP) application that transmits files between a client and a server using Python. Your programs should implement four FTP commands: (1) change directory (cd), (2) list directory content (ls), (3) copy a file from client to a server (put) and (4) copy a file from a server to a client (get). Implement two versions of the program: one that uses stock TCP for...
Please complete in Python and neatly explain and format code. Use snake case style when defining...
Please complete in Python and neatly explain and format code. Use snake case style when defining variables. Write a program named wordhistogram.py which takes one file as an argument. The file is an plain text file(make your own) which shall be analyzed by the program. Upon completing the analysis, the program shall output a report detailing the shortest word(s), the longest word(s), the most frequently used word(s), and a histogram of all the words used in the input file. If...
Please complete in Python and neatly explain and format code. Use snake case style when defining...
Please complete in Python and neatly explain and format code. Use snake case style when defining variables. Write a program named wordhistogram.py which takes one file as an argument. The file is an plain text file(make your own) which shall be analyzed by the program. Upon completing the analysis, the program shall output a report detailing the shortest word(s), the longest word(s), the most frequently used word(s), and a histogram of all the words used in the input file. If...
Complete the following code segment that is intended to extract the Dirham and fils values from...
Complete the following code segment that is intended to extract the Dirham and fils values from a price given as a floating-point value; for example, a price 2.95 yields values 2 and 95 for the dirham and fils. as per the following description: Assign the price to an integer variable named dirham to get the dirhmas part of the price Subtract dirham from price then multiply the difference by 100 and add 0.5 Assign the result to an integer variable...
PYTHON CODE: def square_matrix_multiplication(matrix1,matrix2): C=[[0 for i in range(len(matrix1))] for i in range(len(matrix2))] for i in...
PYTHON CODE: def square_matrix_multiplication(matrix1,matrix2): C=[[0 for i in range(len(matrix1))] for i in range(len(matrix2))] for i in range(len(matrix1)): for j in range(len(matrix2[0])): C[i][j]=0 for k in range(len(matrix2)): C[i][j] += matrix1[i][k]*matrix2[k][j]    return C I use that function in my code. When I type like "return C", It does not work. If I type print(C), then my code works. Why is it happening? I created two user-entered matrices above the function, then I called the function.
Python Stack: The following was done already in the Lab in the Stacks Module with Doubly...
Python Stack: The following was done already in the Lab in the Stacks Module with Doubly Linked List. Create an application to help you stack and un-stack containers in the ship. Create a class called container which will have the object (data), the link (next) Create a class called Pod which is Stack. Include methods addContainer and removeContainer Implement these classes by creating multiple containers to go inside the pod. ADD the Following feature: Include a class attribute in the...
Solve with Python: The following is the color code of the jackets of employees for a...
Solve with Python: The following is the color code of the jackets of employees for a companies annual conference. The Color is determined by the Employee category and the state in which they work. Employee Category Executive (1) Director(2) Manager(3) Worker(4) State Jacket Color State Jacket Color State Jacket Color State Jacket Color NY, NJ, PA Blue NY, NJ, PA Purple NY, NJ, PA Red NY, NJ, PA Black TX, LA, FL White TX, LA, FL Green TX, LA, FL...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided for you to use: def close_enough(x, y, maximum_allowable_difference): My biggest piece of advice to you is to go one line at a time and check your return values after each little change you make. Starter code: # There are different ways of implementing the same idea in math. # Today we will explore a simple way to calculate square roots. # # # #...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT