Skip to content

Latest commit

 

History

History
48 lines (28 loc) · 2.03 KB

python.md

File metadata and controls

48 lines (28 loc) · 2.03 KB

Basic Python quiz

Write code in Python which accomplishes each of the following tasks. Complete individually, and submit to Rebekah in a Slack DM. If you've never coded in Python before, you'll have to do some self-paced learning first. I recommend using LearnPython.org and completing everything up to and including the Dictionaries module.

Tasks

Task 1: Adding machine

Write a function that adds two numbers x,y and returns the output x + y. Sample input might be x=-1, y=8 in which case the expected output is 7. The expected output is either float or int.

Task 2: Character count

Write a function that takes two arguments

  • s an arbitrary string.
  • l a letter (i.e. any valid single character).

The function should search the string for occurences of the letter and return an integer indicating how many times the letter l occurs in the string s.

Note: Your function should be case-insensitive, i.e. it shouldn't care if the letter is "H" or "h"

Task 3: Function isEven

Write a function which evaluates if a given integer number (given as a parameter for the function) is an even number. The function should return a Boolean value True if the number is even and False if the number is odd. Given a list (or array) of n integer numbers, write a program which uses the function isEven to determines the number of even items in the list.

Task 4: Search in List

Given a list (or array) of n floating-point numbers, write a program which searches and outputs the largest number in the list.

Task 5: String and Loops

Write a function which takes a string (word) as an argument. The function should print the complete word on the first line and remove the last character on each successive line, ending with a single (the first) character. Example: Input word is Test Function output: Test Tes Te

Task 6: Get dict keys

Write a function that takes as it's single input any dictionary The function should return the keys of the input dictionary, in a list.