Codingbat - Python-Warm Ups

The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we’re on vacation. Return True if we sleep in.

We have two monkeys, a and b, and the parameters a_smile and b_smile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return True if we are in trouble.

Given two int values, return their sum. Unless the two values are the same, then return double their sum.

Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.

We have a loud talking parrot. The “hour” parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return True if we are in trouble.

Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10.

Given 2 int values, return True if one is negative and one is positive. Except if the parameter “negative” is True, then return True only if both are negative.

Given a string, return a new string where “not “ has been added to the front. However, if the string already begins with “not”, return the string unchanged.

Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..len(str)-1 inclusive).

Given a string, return a new string where the first and last chars have been exchanged.

Given a string, we’ll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front.

Given a string and a non-negative int n, return a larger string that is n copies of the original string.

Given a string and a non-negative int n, we’ll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front

Given a string, return a new string made of every other char starting with the first, so “Hello” yields “Hlo”.

Given a non-empty string like “Code” return a string like “CCoCodCode”.

Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so “hixxxhi” yields 1 (we won’t count the end substring).

Given an array of ints, return the number of 9’s in the array.

Given an array of ints, return True if one of the first 4 elements in the array is a 9. The array length may be less than 4.

Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere.

Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So “xxcaazz” and “xxbaaz” yields 3, since the “xx”, “aa”, and “az” substrings appear in the same place in both strings.

--

--

--

Data Science Enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How you can save up to 80% on the Gas fee? | Block miners’ dilemma

How To Make a Home Media Server.

Abstraction in Software Engineering

Data Science on Your iPad

Is It Done Yet?: My Journey Into Digital Project Management

Automating social media marketing with Python — Chapter 4: Handle Images

Java Autoboxing and Unboxing with examples

Changing The World Without Selling Out As A Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
@IanChriste

@IanChriste

Data Science Enthusiast

More from Medium

Why Learning Programming Takes Time

List and Tuple -Why use a tuple rather of a list?

Customize your command line interface in Python

Command line

The Perks of Learning Python as a Programming Language