← Back to all posts
##### Python Quiz
MariglenMjeshtr

Q1. [User defined funtion] Define a function named "mult()", which can compute the product of two numbers and return the value.

Q2. [User-defined function] Define a function named "odd_or_even" with one argument. It accepts an integer as input value and print out if the input integer is an "odd" or "even" number.

Q3. [User-defined function] Define a function which accepts two inputs, i.e. a lower bound and an upper bound. The function can generate and print 10 RANDOM values between the upper bound and upper bound (both included).

Q4. [String] Consider the following string:

"I like Pizza Very much, because it is good."

a. Write a program to count the number of letters in the string.

b. Write a program to count and print out the number of upper-case letters and lower-case letters in the string.

c. Write a program to extract all upper case letters and print them in console.

d. Write a program to replace all the "i" of all odd orders (the first, third, fifth, etc.) in the string with the symbol "*" and print out the modified string.

e. Writing a program to print the string in reverse order.

f. Write a program to split the string into three substrings separated by comma.

Q5. [List] Given the following list:

[10,25,78,90,35,100,4,7,19,24,29,42,63,21,34,9,4,77]

a. Write a program to extract and print all even numbers in the list.

b. Write a program to compute and print the squared values of all numbers in the list.

c. Write a program to split the list into three equal-length lists and print them.

d. Write a program to create a new list which contains all numbers in the list in REVERSE order.

e. Write a program to delete numbers that are divisible by 5 OR 7 and print the resulting list.

Q6. [Loops and flow control]

a. Write a program to calculate the sum fo all numbers from 0 to 999,999.

b. Write a program to calculate the sum fo all numbers from 0 to 999,999 that are multiples of 5 or 7:

Q7. [A real (fun) problem] If Steve tells you that there are 45 heads and 122 legs among the ducks and dogs on his farm, how many ducks and how many dogs does Sheve have?

a. Write a program to find the solution to this problem.