In: Computer Science
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.
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: