Python: Given a list named listOfThings, write a function that prints out if there are an odd number of things in the list or an even number of things in the list.
If there is an even number of things, your function should print
There is an even number of items in the list.
If there is an odd number of things, your function should print
There is an odd number of items in the list.
Use the following function header
def printOddOrEven(listOfThings)
def printOddOrEven(listOfThings):
e=0
o=0
for i in listOfThings:
if i%2==0:
e=e+1
o=o+1
if e>0:
print("There is an even number of items in the list.")
if o>0:
print("There is an odd number of items in the list.")
listOfThings = []
n = int(input("Enter number of elements : "))
for i in range(0, n):
ele = int(input())
listOfThings.append(ele)
printOddOrEven(listOfThings)
Python: Given a list named listOfThings, write a function that prints out if there are an...
In python
Write a function named printList to print the elements of a list with labels showing each element's order in the list. The function header should like this: def printList(aList): And here is an example run: > > > myList = [92.5, 127.1, 9, 104.2, 78.4] > > > printList(myList) 0 92.5 1 127.1 2 9 3 104.2 4 78.4 Test your function from the Python shell window on various types of lists with varying lengths.
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Write a python function that prints all odd numbers between two given numbers print_odd_numbers(10,20) → 11 13 15 17 19 print_odd_numbers(4,12) → 5 7 9 11 ### Your code here def print_odd_numbers(n1, n2):
Write a Python function named print_nums that takes a single parameter, a list of float values, and prints out the list on a single line.enclosed in brackets, each value with three places after the decimal point, the values separated by two spaces. You do not have to provide comments for this code. Example 1: print_nums([3/3, 4/3, 573, 6/3]) prints: [1.000 1.333 1.667 2.000] Example 2: print_nums([3]) prints: [3.000] Example 3: print_nums([]) prints: []
Write a python function that can find the average of given list of numbers. It prints all numbers whose values is less than the average on the screen. Demonstrate with three example data on how it works?
Using Python write a program that reads an int N >= 0, then prints out each of the following patterns of *. If you do NOT use the string repetition operator * in either problem, you will earn 0.25 points of Extra Credit for each. Also, each pattern must be output via a single function call to the given named function with single parameter N. Examples for N==4 follow, with explanations of how the displayed diagram reflects this value of...
Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...
Ex1 In Python Write a while loop that prints out a list containing the first 5 numbers that are multiples of 9 from 1 to 100. (Hint: use break statement) The output should be [9, 18, 27, 36, 45]
Using Python Write a program that reads an int N >= 0, then prints out each of the following patterns of *. Here, you may use the * repetition operator, if you wish. Also, each pattern must be output via a single function call to the given named function with single parameter N. Examples for N==4 follow, with explanations of how the displayed diagram reflects this value of N: ) Square with number diagonals, with outer side length of N,...
Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here