Answer:
Python code is explained below
Explanation:
CODE(TEXT): -
9A.py:-
def sentence(): #function to read input and display
name = input("Enter a name: ") #input name
place = input("Enter a place: ") #input place
number = int(input("Enter a number: ")) #input number typecasted to int
noun = input("Enter a plural noun: ") #input plural noun
adjective = input("Enter an adjective: ") #input adjective
print("\n{} went to {} to buy {} different types of {}".format(name, place, number, noun)) #format is used to display o/p
print("but unfortunately, the {} were all {} so {} went back to {} to return them.\n".format(noun, adjective,name, place))
op = "n" #initially op = n i.e. user not wanting to quit
while op != "y" : #while user does not input y
sentence() #input words from user
op = input("Do you want to quit [y/n]? ") #prompt to continue or quit
if op == "y": #if yes then print goodbye and exit
print("Goodbye")
break
else: #else print newline and take input
print("")
9B.py: -
#inputs are strings by default applying a split() function to a string splits it into a list of strings
#then with the help of map() function we can convert all the strings into integers
numbers = list(map(int, input("Enter the input: ").split()))
sum = 0 #sum is initially 0
for i in range(len(numbers)): #loops for all the elements in the list
sum = sum + numbers[i] #add the content of current element to sum
avg = sum/ len(numbers) #average = (sum of all elements)/ number of elements in the list
max = numbers[0] #initially max = first number
for i in range(1, len(numbers)): #loops for all remaining elements
if numbers[i] > max : #if their content is greater than max
max = numbers[i] #update max
print("The average and max are: {:.2f} {}".format(avg, max)) #format is used to print in formatted form
#.2f is used to print only 2 digits after decimals
9C.py: -
#inputs are strings by default applying a split() function to a string splits it into a list of strings
#then with the help of map() function we can convert all the strings into integers
numbers = list(map(int, input("Enter a list of numbers: ").split()))
numbers = [elem for elem in numbers if elem >= 0] #using list comprehension
#loops for all elements of the list and keep only those who are >= 0
numbers.sort() #list inbuilt function to sort items
print("The non-negative and sorted numbers are: ", end = "")
for num in numbers: #for all numbers in the list print them
print("{} ".format(num), end = "")