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...
Convert this code written in Python to Java: # Definition of a function isprime(). def isprime(num):...
Convert this code written in Python to Java: # Definition of a function isprime(). def isprime(num):     count=2;     flag=0;     # Loop to check the divisors of a number.     while(count<num and flag==0):         if(num%count!=0):             # Put flag=0 if the number has no divisor.             flag=0         else:             # Put flag=1 if the number has divisor.             flag=1         # Increment the count.         count=count+1     # Return flag value.     return flag # Intialize list. list=[]...
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...
Can you convert this code (Python) to C++ def decrypt(message, key): decryptedText = "" for i...
Can you convert this code (Python) to C++ def decrypt(message, key): decryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k decryptedText += chr(xor) return decryptedText def encrypt(message, key): encryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k encryptedText += chr(xor) return encryptedText # main function userText = input("Enter text: ") userKey = str(input("Enter a key: ")) encryptedMessage = encrypt(userText, userKey)...
Please break down this python code into steps on how to do it. def membership(sequence, value):...
Please break down this python code into steps on how to do it. def membership(sequence, value): if value in sequence: return value if [value] in sequence: return [value] if [[value]] in sequence: return [[value]] a_list = ['a', ['a'], [['a']]] print(membership(a_list, 'a'))
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...
please give complete code in python using def function thank you! Validate Credit Card Numbers Credit...
please give complete code in python using def function thank you! Validate Credit Card Numbers Credit card numbers can be quickly validated by the Luhn checksum algorithm. Start at the rightmost digit save one (the last being the checksum digit). Moving left, double the value of every second digit. If the doubled value is greater than nine, then subtract 9 from the doubled value to renormalize within the range 0–9. Sum all the digits including the checksum digit. If this...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT