text
stringlengths
37
1.41M
""" 剑指 Offer 25. 合并两个排序的链表 输入两个递增排序的链表,合并这两个链表并使新链表中的节点仍然是递增排序的。 示例1: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 限制: 0 <= 链表长度 <= 1000 注意:本题与主站 21 题相同:https://leetcode-cn.com/problems/merge-two-sorted-lists/ date : 12-16-2020 """ # Definition for singly-linked list. from typing import Optional class ListNode: ...
""" 82. 删除排序链表中的重复元素 II 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。 示例 1: 输入: 1->2->3->3->4->4->5 输出: 1->2->5 示例 2: 输入: 1->1->1->2->3 输出: 2->3 date: 2021年3月25日 """ # Definition for singly-linked list. class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class S...
""" 剑指offer 08 二叉树的下一个节点 给定一棵二叉树和其中的一个节点,如何找出中序遍历序列的下一个节点? 3 / \ 9 20 / \ 15 7 inorder : 9 3 15 20 7 input : 15 oupyt : 20 date : 9-23-2020 """ from python.binaryTree import TreeNode """ class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = ...
""" 剑指 Offer 56 - II. 数组中数字出现的次数 II 在一个数组 nums 中除一个数字只出现一次之外,其他数字都出现了三次。 请找出那个只出现一次的数字。 示例 1: 输入:nums = [3,4,3,3] 输出:4 示例 2: 输入:nums = [9,1,7,9,7,9,7] 输出:1 限制: 1 <= nums.length <= 10000 1 <= nums[i] < 2^31 date: 2021年3月5日 """ from typing import List class Solution: def singleNumber(self, nums: List[int]) -> i...
""" 剑指 Offer 49. 丑数 我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。 求按从小到大的顺序的第 n 个丑数。 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。 说明: 1 是丑数。 n 不超过1690。 注意:本题与主站 264 题相同:https://leetcode-cn.com/problems/ugly-number-ii/ date: 2021年3月3日 """ class Solution: def nthUglyNumber(self, n: int) -> int...
""" 322. 零钱兑换 给定不同面额的硬币 coins 和一个总金额 amount。 编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。 你可以认为每种硬币的数量是无限的。 示例 1: 输入:coins = [1, 2, 5], amount = 11 输出:3 解释:11 = 5 + 5 + 1 示例 2: 输入:coins = [2], amount = 3 输出:-1 示例 3: 输入:coins = [1], amount = 0 输出:0 示例 4: 输入:coins = [1], amount = 1 输出:1 示例 5: 输入:coins = [1]...
# Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def preorderTraverse(self): if self: print(self.val) if self.left: self.left.preTraverse() ...
""" 1047. 删除字符串中的所有相邻重复项 给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们。 在 S 上反复执行重复项删除操作,直到无法继续删除。 在完成所有重复项删除操作后返回最终的字符串。答案保证唯一。 示例: 输入:"abbaca" 输出:"ca" 解释: 例如,在 "abbaca" 中,我们可以删除 "bb" 由于两字母相邻且相同,这是此时唯一可以执行删除操作的重复项。 之后我们得到字符串 "aaca",其中又只有 "aa" 可以执行重复项删除操作,所以最后的字符串为 "ca"。 提示: 1 <= S.length <= 20000 S 仅由小写英文字母组成。 date: 2...
""" 剑指 Offer 24. 反转链表 定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 限制: 0 <= 节点个数 <= 5000 注意:本题与主站 206 题相同:https://leetcode-cn.com/problems/reverse-linked-list/ date : 12-22-2020 """ # Definition for singly-linked list. class ListNode: def __init__(self, x): se...
""" 有一个无向的 星型 图,由 n 个编号从 1 到 n 的节点组成。 星型图有一个 中心 节点,并且恰有 n - 1 条边将中心节点与其他每个节点连接起来。 给你一个二维整数数组 edges ,其中 edges[i] = [ui, vi] 表示在节点 ui 和 vi 之间存在一条边。 请你找出并返回 edges 所表示星型图的中心节点。 示例 1: 输入:edges = [[1,2],[2,3],[4,2]] 输出:2 解释:如上图所示,节点 2 与其他每个节点都相连,所以节点 2 是中心节点。 示例 2: 输入:edges = [[1,2],[5,1],[1,3],[1,4]] 输出:1 提示: 3 <= n <= ...
""" 剑指 Offer 67. 把字符串转换成整数 写一个函数 StrToInt,实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。 当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号; 假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。 该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可以被忽略,它们对于函数不应该造成影响。 注意: 假如该字符串中的第一个非空格字符不是一个有效整数字符、字符串为空或字符串仅包含空白字符时,则...
""" 剑指 Offer 35. 复杂链表的复制 请实现 copyRandomList 函数,复制一个复杂链表。 在复杂链表中,每个节点除了有一个 next 指针指向下一个节点, 还有一个 random 指针指向链表中的任意节点或者 null。 https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/ date : 1-25-2021 """ # Definition for a Node. from typing import List class Node: def __init__(self, x: int, next: 'Node' =...
""" 剑指 Offer 53 - I. 在排序数组中查找数字 I 统计一个数字在排序数组中出现的次数。 示例 1: 输入: nums = [5,7,7,8,8,10], target = 8 输出: 2 示例 2: 输入: nums = [5,7,7,8,8,10], target = 6 输出: 0 限制:0 <= 数组长度 <= 50000 注意:本题与主站 34 题相同(仅返回值不同):https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/ date: 2021年2月25日 """ cla...
__author__ = 'Edward' import sys def shortest_path(airports, city_to_code, departure, destination): starting_point = city_to_code[departure.lower()] ending_point = city_to_code[destination.lower()] distance = {} visited = {} previous = {} for airport in airports: distance[airport] = sy...
def validador(sequencia: list) -> bool: abertura = ["[", "{", "("] fechamento = ["]", "}", ")"] pilha = [] if len(sequencia) % 2 != 0 and len(sequencia) == 0: return False for i in sequencia: if i in abertura: pilha.append(i) elif i in fechamento: ...
# Linked List # an AnyList is one of # - None, or # a Pair(first, rest) class Pair: def __init__(self, first, rest): self.first = first # any data type self.rest = rest # an AnyList def __eq__(self, other): return (type(other) == Pair and self.first == other...
s,h=input().split() s=int(s) h=int(h) a=(2*s)/h print('%.2f'% a)
""" For this exercise, we will keep track of when our friend’s birthdays are, and be able to find that information based on their name. Create a dictionary (in your file) of names and birthdays. When you run your program it should ask the user to enter a name, and return the birthday of that person back to them. The in...
from re import finditer import requests from bs4 import BeautifulSoup # Display all villagers with simple information def displayAll(): # Target website to scrape website = requests.get('https://nookipedia.com/wiki/Villagers/New_Horizons') soup = BeautifulSoup(website.text,'html.parser') # Target first wikita...
string = raw_input("Enter a word to decode: ") key = int(raw_input("Enter a key: ")) encodedString = "" string = string.lower() for character in string: if character.isalpha(): result = ord(character) + key if result > 122: abovez = result - 122 character = 96 + abovez ...
name = "Guido van Rossum" name = name.lower() print(name.index("v")) print(name[10]) the_list = name.split() print(the_list)
# Counting Strings ####################################################################################################################### # # Alice got a message M. It is in an alien language. A string in an alien language is said to be valid # if it contains the letter a or z. Alice decided to count the number o...
# Two Strings Game ####################################################################################################################### # # Consider the following game for two players: # There are two strings A and B. Initially, some strings A' and B' are written on the sheet of paper. A' is always # a substr...
# 1.4 Review of Basic Python # 1.4.1 Getting Started with Data print("Algorithms and Data Structures") # Built-in Atomic Data Types print(2+3 * 4) print((2+3) * 4) print(2**10) print(6/3) print(7/3) print(7//3) print(7%3) print(3/6) print(3//6) print(3%6) print(2**100) True False False or True not (False or True) Tr...
# Jiva, The Self Driven Car ####################################################################################################################### # # Jiva is a self driven car and is out on its very first drive. It aims to earn some revenue by serving # as taxi driver. It starts its journey from a point and trav...
# Xsquare And Number List ####################################################################################################################### # # Xsquare loves to play with numbers a lot. Today, he has a multi set S consisting of N integer elements. # At first, he has listed all the subsets of his multi set S ...
# Signal Range ####################################################################################################################### # # Various signal towers are present in a city.Towers are aligned in a straight horizontal line(from left to right) # and each tower transmits a signal in the right to left direct...
# Exceptions as APIs ################################################################################ # run simple square root program python3 module/roots1.py # try to calculate square root of (-1) # print(sqrt(-1)) # throws error # ZeroDivisionError: float division by zero python3 module/roots2.py # handle excepti...
# Cats Substrings ####################################################################################################################### # # There are two cats playing, and each of them has a set of strings consisted of lower case English letters. # The first cat has N strings, while the second one has M strings....
# Generators ################################################################################ def gen123(): yield 1 yield 2 yield 3 g = gen123() g next(g) next(g) next(g) # StopIteration next(g) for v in gen123(): print(v) h = gen123() i = gen123() h i h is i next(h) next(h) next(i) next(i) def ...
# Bon Appétit ####################################################################################################################### # # Anna and Brian order n items at a restaurant, but Anna declines to eat any of the kth item (where 0 <= k <n ) due # to an allergy. When the check comes, they decide to split the...
# Good Subarrays ####################################################################################################################### # # Rhezo likes the problems about subarrays . Today, he has an easy problem for you, but it isn't easy for him. # Can you help Rhezo solve it? The problem is as follows. # You...
# Remove Friends ####################################################################################################################### # # After getting her PhD, Christie has become a celebrity at her university, and her facebook profile is full of # friend requests. Being the nice girl she is, Christie has acce...
# Last Occurrence ####################################################################################################################### # # You have been given an array of size N consisting of integers. In addition you have been given an element # M you need to find and print the index of the last occurrence of ...
# Most Common ####################################################################################################################### # # You are given a string S. # The string contains only lowercase English alphabet characters. # Your task is to find the top three most common characters in the string S. # # ...
# More on List ################################################################################ w = "the quick brown fox jumps over the lazy dog".split() w i = w.index('fox') i w[i] w.index('unicorn') # ValueError: 'unicorn' is not in list w.count('the') 37 in [1, 78, 9, 37, 34, 53] 78 not in [1, 78, 9, 37, 34, 53] u...
# Sherlock and Anagrams ####################################################################################################################### # # Given a string S, find the number of "unordered anagrammatic pairs" of substrings. # # Input Format # First line contains T, the number of testcases. Each testcase c...
# Gaming Triples ####################################################################################################################### # # All the Games are not Mathematical at all but Mathematical games are generally favourite of all. Ananya offered # such a Mathematical game to Sarika. Ananya starts dictating ...
# Nice Arches ####################################################################################################################### # # Nikki's latest work is writing an story of letters. However, she finds writing story so boring that, after # working for three hours, she realized that all she has written are M...
# Maximum occurrence ####################################################################################################################### # # You are given a string which comprises of lower case alphabets (a-z), upper case alphabets (A-Z), numbers, (0-9) # and special characters like !,-.; etc. # You are supp...
# Range ################################################################################ # arithmatic progression of integers range(5) for i in range(5): print(i) range(5,10) list(range(5,10)) list(range(10,15)) #optional step argument list(range(0,10,2)) # abusing range (don't use un-pythonic way) # python is n...
class Square: def __init__(self, side): self.side = side def __add__(squareOne, squareTwo): return ( (4 * squareOne.side) + (4 * squareTwo.side) ) squareOne = Square(5) squareTwo = Square(10) print("Sum of sides of both the squares =", squareOne + squareTwo)
# Roy and Trains ####################################################################################################################### # # Roy and Alfi reside in two different cities, Roy in city A and Alfi in city B. Roy wishes to meet her in city B. # There are two trains available from city A to city B. Roy i...
# End Game ####################################################################################################################### # # Black and White are playing a game of chess on a chess board of n X n dimensions. The game is nearing its end. # White has his King and a Pawn left. Black has only his King left. S...
# 8. Errors and Exceptions # 8.1. Syntax Errors # parsing errors # SyntaxError: invalid syntax while True print('Hello world') # 8.2. Exceptions # ZeroDivisionError: division by zero 10 * (1/0) # NameError: name 'spam' is not defined 4 + spam*3 # TypeError: must be str, not int '2' + 2 # 8.3. Handling Exceptions >>...
# Encryption ####################################################################################################################### # # An English text needs to be encrypted using the following encryption scheme. # First, the spaces are removed from the text. Let L be the length of this text. # Then, characters...
# Kinako Bread ####################################################################################################################### # # Tohka's favorite food is kinako bread, but she likes to eat bread in general too. For dinner, Shido has bought # Tohka N loaves of bread to eat, arranged in a line. Of the N lo...
# Quicksort 2 - Sorting ####################################################################################################################### # # In the previous challenge, you wrote a partition method to split an array into two sub-arrays, one containing # smaller elements and one containing larger elements tha...
# Zeros and Ones ####################################################################################################################### # # zeros # The zeros tool returns a new array with a given shape and type filled with 0's. # # import numpy # print numpy.zeros((1,2)) #Default type is fl...
# Cavity Map ####################################################################################################################### # # You are given a square map of size n x n. Each cell of the map has a value denoting its depth. We will call a # cell of the map a cavity if and only if this cell is not on the bo...
# Solve Me First ####################################################################################################################### # # Welcome to HackerRank! The purpose of this challenge is to familiarize you with reading input from stdin # (the standard input stream) and writing output to stdout (the standard ...
# Re.start() & Re.end() ####################################################################################################################### # # start() & end() # These expressions return the indices of the start and end of the substring matched by the group. # Code # >>> import re # >>> m = re.search(r'\...
# 11_dictionaries and tuples d = {"tom": 7326789820, "rob": 7325730239, "joe": 7326789820} print(d) d["tom"] d["sam"] = 739567987 print(d) del d["sam"] print(d) for key in d: print("key :", key, " value :", d[key]) for k,v in d.items(): print("key :", k, " value :", v) "tom" in d "samir" in d d.clear() d ...
# Strange addition ####################################################################################################################### # # HackerMan has a message that he has coded in form of digits, which means that the message contains only numbers # and nothing else. He is fearful that the enemy may get the...
# Dot and Cross ####################################################################################################################### # # dot # The dot tool returns the dot product of two arrays. # # import numpy # A = numpy.array([ 1, 2 ]) # B = numpy.array([ 3, 4 ]) # # print numpy.dot(A, B) #Out...
# Find the Maximum Depth ####################################################################################################################### # # You are given a valid XML document, and you have to print the maximum level of nesting in it. # Take the depth of the root as 0. # # Input Format # The first line...
# Mini-Max Sum ####################################################################################################################### # # Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly # four of the five integers. Then print the respective minimum and m...
# Minimum Distances ####################################################################################################################### # # Consider an array of n integers A =[a0, a1, ....an-1]. The distance between two indices i and j, # is denoted by dij = |i-j|. Given A, find the minimum dij such that ai = ...
# Car Names ####################################################################################################################### # # Brian built his own car and was confused about what name he should keep for it. He asked Roman for help. # Roman being his good friend, suggested a lot of names. # Brian only li...
# Set .intersection() Operation ####################################################################################################################### # # .intersection() # The .intersection() operator returns the intersection of a set and the set of elements in an iterable. # Sometimes, the & operator is used ...
#!/usr/bin/env python3 # # An HTTP server that remembers your name (in a cookie) # # In this exercise, you'll create and read a cookie to remember the name # that the user submits in a form. There are two things for you to do here: # # 1. Set the relevant fields of the cookie: its value, domain, and max-age. # # 2. R...
# Little Ashish and his wife ####################################################################################################################### # # Little Ashish had no interest in studying ever in his life. So, he always wanted to marry as soon as possible, # and kept forcing his parents to get him married. ...
# Modified Kaprekar Numbers ####################################################################################################################### # # A modified Kaprekar number is a positive whole number n with d digits, such that when we split its square into # two pieces - a right hand piece r with d digits an...
# Integers Come In All Sizes ####################################################################################################################### # # Integers in Python can be as big as the bytes in your machine's memory. There is no limit in size as there # is: 2^31 (c++ int) or 2^(63)-1 (C++ long long int). #...
# 5. Data Structures # 5.1. More on Lists x = [1, 2, 3, 4] x.append(5) x[len(x):] = [6] y = ['a', 'b', 'c'] x.extend(y) x[len(x):] = y x.insert(0, 10) x.insert(len(x), 11) x.remove(10) x.remove(y) x.remove(y[0]) x.remove(y[1]) x.remove(y[2]) # ValueError: list.remove(x): x not in list x.remove('d') x.pop(len(x)-1)...
# Battle Of Words ####################################################################################################################### # # Alice and Bob are fighting over who is a superior debater. However they wish to decide this in a dignified # manner. So they decide to fight in the Battle of Words. # In e...
# Alien language ####################################################################################################################### # # Little Jhool considers Jaadu to be a very close friend of his. But, he ends up having some misunderstanding with # him a lot of times, because Jaadu's English isn't perfect, ...
# checking class types and instances class Book: def __init__(self, title): self.title = title class Newspaper: def __init__(self, name) -> None: self.name = name # create some instances of the classes b1 = Book("The Catcher In The Rye") b2 = Book("The Grapes of Wrath") n1 = Newspaper("The W...
# Mars Exploration ####################################################################################################################### # # Sami's spaceship crashed on Mars! She sends n sequential SOS messages to Earth for help. # [NASA_Mars_Rover.jpg] # Letters in some of the SOS messages are altered by cosm...
# Sherlock and Special Count ####################################################################################################################### # # Let's say P= [P1, P2 . . . PN] is a permutations of all positive integers less than or equal to N. # A function called "special count" F(P) is defined as: # (im...
# Running Time of Algorithms ####################################################################################################################### # # In the previous challenges you created an Insertion Sort algorithm. It is a simple sorting algorithm that works # well with small or mostly sorted data. However, ...
# instance methods - methods of a class which uses "self" keyword to access # & modify the instance attirbutes of a class # static method - do not take "self" parameter, with decorator "@staticmethod" # ignore binding of the object # do not modify instance attribut...
# Sock Merchant ####################################################################################################################### # # John's clothing store has a pile of loose socks where each sock is labeled with an integer, , denoting its color. # He wants to sell as many socks as possible, but his custom...
# minimumNumber.py ####################################################################################################################### # # Write two Python functions to find the minimum number in a list. The first function should compare each number # to every other number on the list. O(n 2 ). The second func...
# median.py def median(iterable): """ Obtain the central value of a series. Sorts the iterable and returns the middle value if there is an even number of elements, or the arithmetic mean of the middle two elements if there is an even number of elements. Args: iterable: A series of orderabl...
# gen2 ################################################################################ def distinct(iterable): """Return unique items by eliminating duplicates. Args : iterable : The source series. Yields : Unique elements in order from 'iterable'. """ seen = set() for item ...
#! /usr/bin/env python def madlib(adjective ='thirsty',name = 'adam'): print "the %s %s ate all the pizza" %(adjective,name) madlib() madlib(adjective='hungry',name = 'adam') def shoppingCart(itemName, *avgPrices): for price in avgPrices : print "price: ", price shoppingCart('computer',100,120,34) def shoppingCa...
# Exceptions ####################################################################################################################### # # Exceptions # # Errors detected during execution are called exceptions. # # Examples: # ZeroDivisionError # This error is raised when the second argument of a division or mo...
# Find the Median ####################################################################################################################### # # In the Quicksort challenges, you sorted an entire array. Sometimes, you just need specific information about a # list of numbers, and doing a full sort would be unnecessary....
# ginortS ####################################################################################################################### # # You are given a string S. # S contains alphanumeric characters only. # Your task is to sort the string S in the following manner: # # All sorted lowercase letters are ahead ...
class Fraction: def __init__(self, top, bottom): self.num = top self.den = bottom def show(self): print(self.num, '/', self.den) def __str__(self): return str(self.num) + '/' + str(self.den) def gcd(self, m,n): while m % n != 0: old_m = m ...
# Simple Banking System import random import sqlite3 class SimpleBankingSystem(object): _sqlite3_db_conn = None _sqlite3_cursor = None @staticmethod def print_welcome_message(): print('1. Create an account') print('2. Log into account') print('0. Exit') return int(inpu...
# 10_functions tom_exp_list = [2100, 3400, 3500] joe_exp_list = [200, 500, 700] total = 0 for item in tom_exp_list: total = total + item print("Tom's total expenses: ", total) total = 0 for item in joe_exp_list: total = total + item print("Joe's total expenses: ", total) #####################################...
# List Comprehensions ################################################################################ words = "Why sometimes I have believed as many as six impossible things before breakfast".split() words # list comprehension # [expr(item) for item in iterable] [len(word) for word in words] # declarative imperative ...
# Ambiguous Tree ####################################################################################################################### # # For his birthday, Jeffrey received a tree with N vertices, numbered from 1 to N. Disappointed by the fact that # there is only one simple path between any two vertices, Jeffr...
# Samu and Card Game ####################################################################################################################### # # One day Samu went out for a walk in the park but there weren't any of her friends with her. So she decided # to enjoy by her own. Samu noticed that she was walking in rec...
# Laziness and the Infinite ################################################################################ # infinite loop def lucas(): yield 2 a = 2 b = 1 while True : yield b a, b = b, a+b for x in lucas(): print(x) #############################################################...
# 4.6. Defining Functions # The execution of a function introduces a new symbol table used for the local variables of the function. # variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, # then in the global symbol table, and finally in the table of built-in...
# Min and Max ####################################################################################################################### # # min # The tool min returns the minimum value along a given axis. # # import numpy # my_array = numpy.array([[2, 5], # [3, 7], # ...
class dominosPizzaOrder(): """ usage for creating an object of this class""" orderNum = 0 pizzaNames = ["Margherita", "cornNonion", "FarmHouse", "CountrySpecial", ] pizzaCrusts = ["HandTossed", "ThinCrust", "CheezeBurst", "NewHandTossed"] pizzaToppings = ["Onion", "Tomato", "Capsicum", "C...
# Rest in peace - 21-1! ####################################################################################################################### # # The grandest stage of all, Wrestlemania XXX recently happened. And with it, happened one of the biggest # heartbreaks for the WWE fans around the world. The Undertaker...
# Insertion Sort - Part 2 ####################################################################################################################### # # In Insertion Sort Part 1, you sorted one element into an array. Using the same approach repeatedly, can you sort # an entire unsorted array? # Guideline: You alrea...
# Computer Virus ####################################################################################################################### # # Oh no! The virus infected Nick's computer after he downloaded a bunch of TAS preparation books from BayPirate, # and now he needs your (the best programmer in Lalalandia's) h...
# Unique Subarrays ####################################################################################################################### # # A contiguous subarray is defined as unique if all the integers contained within it occur exactly once. There is # a unique weight associated with each of the subarray. Uniq...
import numpy as np import time import sys # numpy array intro a = np.array([1, 2, 3]) print(a) print(a[0]) print(a[1]) ########################################################################## # array size comparison l = range(1000) print('Python List size: ', sys.getsizeof(5) * len(l)) array = np.arange(1000) pri...
####################################################################################################################### # # startWord # # Given a string and a second "word" string, we'll say that the word matches the string # if it appears at the front of the string, except its first char does not need to matc...
# Two Strings ####################################################################################################################### # # Given two strings a and b, determine if they share a common substring. # # Input Format # The first line contains a single integer p, denoting the number of (a,b) pairs you mu...
""" Output question "What is your name?", "How old are you?", "Where do you live?". Read the answer of user and output next information :"Hello, (answer(name))", 'Your age is (answer(age))', 'You live in (answer(city))' """ name = input('What is your name? ') age = input('How old are you? ') city = input('Where do yo...
#Multiples of 3 or 5 def solution(number): ''' it returns the sum of all the multiples of 3 or 5 below the number passed in''' s = 0 for i in range(1,number): if i%3==0 or i%5==0: s+=i return s
#Simple: Find The Distance Between Two Points def distance(x1, y1, x2, y2): '''function find a distance''' return round((((x2-x1)**2+(y2-y1)**2)**0.5),2)