text
stringlengths
37
1.41M
#!/usr/bin/env python3 # -*- encoding: utf-8 -*- ''' @File : heap_sort.py @Time : 2020/03/25 18:19:01 @Author : cogito0823 @Contact : 754032908@qq.com @Desc : None ''' def heapify(array,index,heap_size): largest = index lchild = index * 2 + 1 rchild = index * 2 + 2 if lchild < heap...
#!/usr/bin/env python3 # -*- encoding: utf-8 -*- ''' @File : stack_binary_tree.py @Time : 2020/03/16 23:15:26 @Author : cogito0823 @Contact : 754032908@qq.com @Desc : 用栈遍历二叉树 ''' class Node(): """节点类""" def __init__(self,data): self.data = data self.left_child = None ...
class MyQueue: def __init__(self, capacity): self.capacity = capacity self.item = [None] * capacity self.head = None self.tail = None self.size = 0 def is_full(self): if self.head is None: return False if (self.tail + 1) % self.capacity == self...
import requests import os yn = 'y' while yn == 'y': os.system('cls') print("Welcome to IsItDown.py!") print("Please write a URL or URLs you want to check. (separated by comma)") urls = input().split() for l in urls: l = l.strip(',') if '.' not in l: print(l, "is not val...
size = 10 i = 0 userValue = [] print("List of Integers: ") while i < size: userValue.append(int(input("Enter an integer: "))) i = i + 1 print("Now the reverse") i = 9 while i >= 0: print(userValue[i]) i = i - 1
valor1 = int(input("Digite um número: ")) valor2 = int(input("Digite outro número: ")) soma = valor1 + valor2 print("A soma entre {} e {} é = {}".format(valor1, valor2, soma))
import numpy as np class LinearClassifier(object): """Implementation of linear classifier with svm and softmax loss functions""" def __init__(self): self.W = None def predict(self, X: np.array) -> np.array: """ predict labels for given data :param X: np.array of shape (num...
# can you use varname for prompt? fname = 'First Name' lname = 'Last Name' #fname = raw_input(prompt) % 'First Name' def getvars(vars): prompt = '%s > ' % vars var = raw_input(prompt) return var fname = getvars(fname) lname = getvars(lname) print '%s %s' % (fname,lname)
# Ejercicio de Calculadora try: number1 = int(input('Valor 1: ')) except: print('Solo Numeros') exit() try: number2 = int(input('Valor 2: ')) except: print('Solo Numeros') exit() operation = input('que operacion quiere realizar +-*/') if operation == '+': print(number1+number2) elif operati...
#!/usr/bin//python3 def ler_arquivo(nome): with open (nome,'r') as arquivo: conteudo = arquivo.read() return conteudo def escrever_arquivo (nome): with open (nome,'a') as arquivo: conteudo = input('digite uma fruta:') arquivo.write(conteudo +'\n') return True def sobrescrever_...
#!/usr/bin//python3 qtd = int(input ('digite um inteiro')) for z in range (qtd): if z ==100: print("encontrei") break else: print('nao encontrei')
soma=0 for x in range (4): nota = float(input('Digite a nota {}: '.format(x+1))) soma +=nota print ('A média é igual há {:.2f}'.format(soma/4))
lower = 10 upper = 100 LowNumber = input("Enter a number ({}-­‐{}): ".format(str(lower), str(upper))) LowNumber = LowNumber.strip() HighNumber = input("Enter a number ({}-­‐{}): ".format(str(LowNumber), str(upper))) HighNumber = HighNumber.strip() for i in range(int(LowNumber), int(HighNumber)): print("{} {}".forma...
import pandas as pd import numpy as np def get_betas(X, Y): """Get betas (according to OLS formula)""" betas = (np.transpose(X) * X)^(-1) * (np.transpose(X) * Y) # transpose is a numpy function print("Working!") return betas def get_residuals(betas, X, Y): """Get residuals (according to OLS formu...
# -*- coding: utf-8 -*- """ Created on Thu Dec 26 18:01:04 2019 @author: soodr """ import tkinter from tkinter import Button from tkinter import Label from tkinter import StringVar from tkinter import Entry from tkinter import messagebox import time def myGame(): window = tkinter.Tk() ...
idade = contM = contH = cont = 0 while True: print('-' * 30) print('CADASTRE UMA PESSOA') print('-' * 30) idade = int(input('Quantos anos você tem?')) sexo = ' ' while sexo not in 'MF': sexo = str(input('Qual é o seu sexo? [M/F]')).strip().upper()[0] ...
print ('='*40) print(' 10 TERMOS DE UMA PA ') termo = int(input('Primeiro termo: ')) razao = int(input('Razão: ')) pa = 0 pa = termo + (10 - 1) * razao for count in range(termo, pa + razao, razao): print('{} '.format(count), end=' ->')
menorP = 0 maiorP = 0 for count in range(1, 6): peso = float(input('Peso da {}ª pessoa: '.format(count))) if count == 1: maiorP = peso menorP = peso else: if peso > maiorP: maiorP = peso if peso < menorP: menorP = peso print('O maior peso lido foi de {...
peso = float(input('Digite seu peso: ')) altura = float(input('Digite sua altura: ')) imc = peso / (altura ** 2) print('Com peso de {}kg e altura de {}m'.format(peso,altura)) if imc <= 18.5: print('Seu IMC está em {}. Você está abaixo do peso'.format(imc)) elif imc <= 25: print('Seu IMC está em {}. Você está no...
##Python 3.7.3 Implementation import math ################### #- Collect input -# ################### def get_input(): ## Get inputs, and store them in an array num_boxes_students = input() boxes, students = num_boxes_students.split() rawArray = [] boxContents = input() return box...
words = [] fileObj = open("ignore_words.txt", "r") # opens the file in read mode words += fileObj.read().splitlines() # puts the file into an array fileObj.close() fileObj = open("common_ignore.txt", "r") # opens the file in read mode words += fileObj.read().splitlines() # puts the file into an array fileObj.close(...
# -*- coding: utf-8 -*- """ Created on Tue Sep 13 20:38:56 2022 @author: Henry """ a=0; z=10; dato=0; for z in range(0,25): z=z+3; print("El valor de z es: ", z);
#Funcion para Crear la matriz def matrizKreator(n,m): A=[] for i in range(n): A.append([]) for j in range(m): A[i].append(int(input("Ingrese la duracion de llamada en segundos: "))) return(A); #Funcion para calcular el promedio de la matriz def prom(A): Agente=0 suma=0 ...
def primo(n): for i in range(2,int(n/2)): if(n%i==0): return False; return True Arr=[13,12,27,31,56,11,10] for i in Arr: if(primo(i)): print("El numero ", i," es primo") else: print("El numero ", i," NO es primo")
#NAND or NOR로 모든 가능한 논리 회로를 구성할 수 있습니다. #실제로 상업적 용도의 flash memory 를 nand/nor 회로로만 구성합니다. #NOR 에 비해 적은 회로로도 구성할 수 있어서 몇 가지 단점에도 불구하고 nand flash memory가 주류 import numpy as np #nand 회로 def NAND(x1, x2): x = np.array([x1, x2]) weight = np.array([-0.5, -0.5]) bias = 0.7 tmp = np.sum(x*weight) + bias if...
# Pro/g/ramming challenges # 69: RPN Calculator # by ahmad89098 def operation(num1, num2): if operator == "+": answer = num1 + num2 elif operator == "-": answer = num1 - num2 elif operator == "*": answer = num1 * num2 elif operator == "/": answer = num1/num...
def count_vals(val_string, count=1): if len(val_string) == 0: return [] elif len(val_string) == 1: return [(val_string, count)] else: if val_string[0] == val_string[1]: return count_vals(val_string[1:], count+1) else: inner = count_vals(val_string[1:])...
# -*- coding: utf-8 -*- ''' File name: code\polar_polygons\sol_465.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #465 :: Polar polygons # # For more information see: # https://projecteuler.net/problem=465 # Problem Statement ''' The k...
# -*- coding: utf-8 -*- ''' File name: code\exploring_pascals_pyramid\sol_154.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #154 :: Exploring Pascal's pyramid # # For more information see: # https://projecteuler.net/problem=154 # Probl...
# -*- coding: utf-8 -*- ''' File name: code\inscribed_circles_of_triangles_with_one_angle_of_60_degrees\sol_195.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #195 :: Inscribed circles of triangles with one angle of 60 degrees # # For mo...
# -*- coding: utf-8 -*- ''' File name: code\harshad_numbers\sol_387.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #387 :: Harshad Numbers # # For more information see: # https://projecteuler.net/problem=387 # Problem Statement ''' A H...
# -*- coding: utf-8 -*- ''' File name: code\integers_with_decreasing_prime_powers\sol_578.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #578 :: Integers with decreasing prime powers # # For more information see: # https://projecteuler.n...
# -*- coding: utf-8 -*- ''' File name: code\four_representations_using_squares\sol_229.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #229 :: Four Representations using Squares # # For more information see: # https://projecteuler.net/pro...
# -*- coding: utf-8 -*- ''' File name: code\permuted_multiples\sol_52.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #52 :: Permuted multiples # # For more information see: # https://projecteuler.net/problem=52 # Problem Statement ''' ...
# -*- coding: utf-8 -*- ''' File name: code\robot_walks\sol_208.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #208 :: Robot Walks # # For more information see: # https://projecteuler.net/problem=208 # Problem Statement ''' A robot mov...
# -*- coding: utf-8 -*- ''' File name: code\incenter_and_circumcenter_of_triangle\sol_496.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #496 :: Incenter and circumcenter of triangle # # For more information see: # https://projecteuler.n...
# -*- coding: utf-8 -*- ''' File name: code\1000digit_fibonacci_number\sol_25.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #25 :: 1000-digit Fibonacci number # # For more information see: # https://projecteuler.net/problem=25 # Proble...
# -*- coding: utf-8 -*- ''' File name: code\the_prime_factorisation_of_binomial_coefficients\sol_231.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #231 :: The prime factorisation of binomial coefficients # # For more information see: # ...
# -*- coding: utf-8 -*- ''' File name: code\möbius_function_and_intervals\sol_464.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #464 :: Möbius function and intervals # # For more information see: # https://projecteuler.net/problem=464 ...
# -*- coding: utf-8 -*- ''' File name: code\ordered_fractions\sol_71.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #71 :: Ordered fractions # # For more information see: # https://projecteuler.net/problem=71 # Problem Statement ''' Co...
# -*- coding: utf-8 -*- ''' File name: code\modular_cubes_part_2\sol_272.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #272 :: Modular Cubes, part 2 # # For more information see: # https://projecteuler.net/problem=272 # Problem Stateme...
# -*- coding: utf-8 -*- ''' File name: code\first_sort_i\sol_523.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #523 :: First Sort I # # For more information see: # https://projecteuler.net/problem=523 # Problem Statement ''' Consider ...
# -*- coding: utf-8 -*- ''' File name: code\maximum_path_sum_ii\sol_67.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #67 :: Maximum path sum II # # For more information see: # https://projecteuler.net/problem=67 # Problem Statement ''...
# -*- coding: utf-8 -*- ''' File name: code\clock_sequence\sol_506.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #506 :: Clock sequence # # For more information see: # https://projecteuler.net/problem=506 # Problem Statement ''' Consi...
# -*- coding: utf-8 -*- ''' File name: code\primitive_triangles\sol_276.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #276 :: Primitive Triangles # # For more information see: # https://projecteuler.net/problem=276 # Problem Statement ...
# -*- coding: utf-8 -*- ''' File name: code\angular_bisectors\sol_257.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #257 :: Angular Bisectors # # For more information see: # https://projecteuler.net/problem=257 # Problem Statement '''...
# -*- coding: utf-8 -*- ''' File name: code\integer_angled_quadrilaterals\sol_177.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #177 :: Integer angled Quadrilaterals # # For more information see: # https://projecteuler.net/problem=177 ...
# -*- coding: utf-8 -*- ''' File name: code\fibonacci_primitive_roots\sol_437.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #437 :: Fibonacci primitive roots # # For more information see: # https://projecteuler.net/problem=437 # Proble...
# -*- coding: utf-8 -*- ''' File name: code\prime_pair_sets\sol_60.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #60 :: Prime pair sets # # For more information see: # https://projecteuler.net/problem=60 # Problem Statement ''' The pr...
# -*- coding: utf-8 -*- ''' File name: code\step_numbers\sol_178.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #178 :: Step Numbers # # For more information see: # https://projecteuler.net/problem=178 # Problem Statement ''' Consider ...
# -*- coding: utf-8 -*- ''' File name: code\gozinta_chains_ii\sol_606.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #606 :: Gozinta Chains II # # For more information see: # https://projecteuler.net/problem=606 # Problem Statement '''...
# -*- coding: utf-8 -*- ''' File name: code\optimum_polynomial\sol_101.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #101 :: Optimum polynomial # # For more information see: # https://projecteuler.net/problem=101 # Problem Statement '...
# -*- coding: utf-8 -*- ''' File name: code\a_rectangular_tiling\sol_405.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #405 :: A rectangular tiling # # For more information see: # https://projecteuler.net/problem=405 # Problem Statemen...
# -*- coding: utf-8 -*- ''' File name: code\triangular_pentagonal_and_hexagonal\sol_45.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #45 :: Triangular, pentagonal, and hexagonal # # For more information see: # https://projecteuler.net/p...
# -*- coding: utf-8 -*- ''' File name: code\biclinic_integral_quadrilaterals\sol_311.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #311 :: Biclinic Integral Quadrilaterals # # For more information see: # https://projecteuler.net/problem...
# -*- coding: utf-8 -*- ''' File name: code\gozinta_chains\sol_548.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #548 :: Gozinta Chains # # For more information see: # https://projecteuler.net/problem=548 # Problem Statement ''' A goz...
# -*- coding: utf-8 -*- ''' File name: code\counting_rectangles\sol_85.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #85 :: Counting rectangles # # For more information see: # https://projecteuler.net/problem=85 # Problem Statement ''...
# -*- coding: utf-8 -*- ''' File name: code\nim_square\sol_310.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #310 :: Nim Square # # For more information see: # https://projecteuler.net/problem=310 # Problem Statement ''' Alice and Bob...
# -*- coding: utf-8 -*- ''' File name: code\mirror_power_sequence\sol_617.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #617 :: Mirror Power Sequence # # For more information see: # https://projecteuler.net/problem=617 # Problem Statem...
# -*- coding: utf-8 -*- ''' File name: code\unfair_race\sol_573.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #573 :: Unfair race # # For more information see: # https://projecteuler.net/problem=573 # Problem Statement ''' $n$ runners...
# -*- coding: utf-8 -*- ''' File name: code\pivotal_square_sums\sol_261.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #261 :: Pivotal Square Sums # # For more information see: # https://projecteuler.net/problem=261 # Problem Statement ...
# -*- coding: utf-8 -*- ''' File name: code\stone_game_ii\sol_325.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #325 :: Stone Game II # # For more information see: # https://projecteuler.net/problem=325 # Problem Statement ''' A game ...
# -*- coding: utf-8 -*- ''' File name: code\counting_binary_matrices\sol_626.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #626 :: Counting Binary Matrices # # For more information see: # https://projecteuler.net/problem=626 # Problem ...
# -*- coding: utf-8 -*- ''' File name: code\rational_zeros_of_a_function_of_three_variables\sol_180.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #180 :: Rational zeros of a function of three variables # # For more information see: # ht...
# -*- coding: utf-8 -*- ''' File name: code\steps_in_euclids_algorithm\sol_433.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #433 :: Steps in Euclid's algorithm # # For more information see: # https://projecteuler.net/problem=433 # Pro...
# -*- coding: utf-8 -*- ''' File name: code\a_weird_recurrence_relation\sol_463.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #463 :: A weird recurrence relation # # For more information see: # https://projecteuler.net/problem=463 # Pr...
# -*- coding: utf-8 -*- ''' File name: code\goldbachs_other_conjecture\sol_46.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #46 :: Goldbach's other conjecture # # For more information see: # https://projecteuler.net/problem=46 # Proble...
# -*- coding: utf-8 -*- ''' File name: code\sum_of_a_square_and_a_cube\sol_348.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #348 :: Sum of a square and a cube # # For more information see: # https://projecteuler.net/problem=348 # Prob...
# -*- coding: utf-8 -*- ''' File name: code\pandigital_multiples\sol_38.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #38 :: Pandigital multiples # # For more information see: # https://projecteuler.net/problem=38 # Problem Statement ...
# -*- coding: utf-8 -*- ''' File name: code\triangle_on_parabola\sol_397.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #397 :: Triangle on parabola # # For more information see: # https://projecteuler.net/problem=397 # Problem Statemen...
# -*- coding: utf-8 -*- ''' File name: code\number_sequence_game\sol_477.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #477 :: Number Sequence Game # # For more information see: # https://projecteuler.net/problem=477 # Problem Statemen...
# -*- coding: utf-8 -*- ''' File name: code\π_sequences\sol_609.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #609 :: π sequences # # For more information see: # https://projecteuler.net/problem=609 # Problem Statement ''' For every $n...
# -*- coding: utf-8 -*- ''' File name: code\diophantine_reciprocals_i\sol_108.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #108 :: Diophantine reciprocals I # # For more information see: # https://projecteuler.net/problem=108 # Proble...
# -*- coding: utf-8 -*- ''' File name: code\divisibility_comparison_between_factorials\sol_383.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #383 :: Divisibility comparison between factorials # # For more information see: # https://proj...
# -*- coding: utf-8 -*- ''' File name: code\migrating_ants\sol_393.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #393 :: Migrating ants # # For more information see: # https://projecteuler.net/problem=393 # Problem Statement ''' An n...
# -*- coding: utf-8 -*- ''' File name: code\squarefree_fibonacci_numbers\sol_399.py Author: Vaidic Joshi Date created: Oct 20, 2018 Python Version: 3.x ''' # Solution to Project Euler Problem #399 :: Squarefree Fibonacci Numbers # # For more information see: # https://projecteuler.net/problem=399 # ...
# -*- coding: utf-8 -*- """ Created on Sun Aug 30 00:20:04 2020 @author: frmendes If n=1, the sequence is composed of a single integer: 1 If n is even, the sequence is composed of n followed by sequence h(n/2) If n is odd, the sequence is composed of n followed by sequence h(3⋅n+1) global sum """ import sys n ...
###### Function : get_gravitational_force ###### Paremters: 3 floating point numbers, 2 corresponding to two different masses, 1 corresponding to the distance between them ###### Preconditions: all three parameters must be in manipulatable floating point form ###### Postconditions: None. def get_gravitational_force(ma...
# ENME 489Y: Remote Sensing # Grayscale algorithm & comparison with OpenCV # Import packages import numpy as np import cv2 import imutils print "All packages imported properly!" # Load & show original image image = cv2.imread("testudo.jpg") true = image.copy() cv2.imshow("Original Image", image) print "height: %d"...
# ENME489Y: Remote Sensing # import the necessary packages import numpy as np import time import cv2 import imutils import os # allow the camera to setup time.sleep(1) # Enter the initial IMU angle from user d = raw_input("Please enter IMU angle: ") print "Confirming the IMU angle you entered is: " print d # The fo...
import time def countdown(seconds): i = 0 while i < seconds: print seconds seconds -=1 time.sleep(1) print "End countdown" countdown(int(raw_input("Please enter the number of seconds")))
import sys def check_row(row,value): if value in board[row]: return False return True def check_column(column,value): for i in range(9): if value == board[i][column] : return False return True def check_box(row,column,value): idx = [row // 3 * 3, column // 3 * 3] for i in range(3): ...
import fractions n = int(input()) t = list(map(int,input().split())) first,t = t[0],t[1:] for i in t: tmp = fractions.Fraction(i,first) print(str(tmp.denominator)+'/'+str(tmp.numerator))
def check_sosu(end): for i in range(2, end+1): if is_sosu[i]: try: for j in range(2, end+1): is_sosu[i*j] = False except: continue start, end = map(int, input().split()) is_sosu = [True for _ in range(end+1)] is_sosu[0], is_sosu[1...
menu = [int(input()) for i in range(5)] print(min(menu[:3])+min(menu[3:])-50)
import requests from typing import List from lib.types import Stop from lib.utils import validate_number_choice def fetch_stops(route_id: str, direction_index: int) -> List[Stop]: """ Fetches a list of stops for a given route and direction from the MBTA API. """ try: response = requests.get( ...
import numpy as np # as se hum kisi bhi moduleko chota ker ke use ka name change ker sakete he a=np.array([1,2,3,4,5,6,7,8,9,0]) b=np.array([1,2,3,4,5,6,7,8,9,0]) print(a) print(b) print(a+b) print(a+2) print(a*2) print(a**2) print(a/2)
#Question 1 #Create an Array in python using the list and perform delete from any position operation l=list(map(int,input().split())) k=int(input("enter the position to be deleted")) l.pop(k-1) print("Numbers of list after removal ") print(*l)
primes = [2, 3, 5, 7] planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'] hands = [ ['J', 'Q', 'K'], ['2', '2', '2'], ['6', 'A', 'K'], # (Comma after the last element is optional) ] hands = [['J', 'Q', 'K'], ['2', '2', '2'], ['6', 'A', 'K']] # A list can c...
class Node: def __init__(self , data): self.data = data self.next = None self.prev = None class doubly_linkedlist: def __init__(self): self.head = None def append(self,data): if self.head == None: # no element is there new_node = Node(data) ...
from functools import partial from typing import Callable, List, Type, Union, Iterable from ....excepts import LookupyError def iff(precond: Callable, val: Union[int, str], f: Callable) -> bool: """If and only if the precond is True Shortcut function for precond(val) and f(val). It is mainly used to cre...
# def solution(arr, divisor): # answer = [] # for i in arr: # if i % divisor == 0: # answer.append(i) # answer.sort() # if len(answer) == 0: # answer = [-1] # # return answer #list comprehension def solution(arr, divisor): array = [x for x in arr if x % divisor == 0]...
#Making a digital clock with Python import time import tkinter as tk from tkinter import * def tick(time1=''): #Get the current local time from the PC time2 = time.strftime('%I:%M:%S') #if the time string has changes, update it if time2 != time1: time1 = time2 clock_frame.config(text=t...
# variables var1 = 10 # int var2 = 4.5 # float var3 = "bonjour" # string var4 = True # boolean var5 = ["bonjour", 5 , 3.5] # list print("total est egal a :") total = var1 + var2 print(total) # conditions if var1 > var2: print("c'est plus grand") elif var1 < var2: print("c'est plus petit") else: print("c'...
import unittest '''The merge sort starts by slicing the array into smaller pieces by half till the array has onle 1 element then we start sorting and merging from there in the helper method, I need to make sure that I am accounting for the cases where the left is done before the right and continoue the missing one'''...
temp = list(range(1,6)) N = len(temp) for i in range(N): for j in range(N - 1): print(temp) a = temp[j] b = temp[j + 1] temp[j] = b temp[j + 1] = a
from itertools import permutations def solution(card, n): answer = -1 idx = 0 ans = [] n = tuple(map(int, str(n))) for i in permutations(card): print(i) ans.append(i) ans = sorted(set(ans)) for i in ans: if n == i: return idx + 1 idx += 1 re...
# 2947 def printList(L): for i in range(len(L)): print(L[i], end=" ") print() inputList = list(map(int, input().split())) sortedList = sorted(inputList) while inputList != sortedList: for i in range(len(inputList) - 1): if inputList[i] > inputList[i + 1]: temp = inputList[i + ...
from collections import Counter sentence = input("Enter the string: ") res = Counter(sentence) max_key = max(res, key = res.get) print(max_key, res[max_key])
def construct_trie(): root = dict() with open("scrabble-dictionary.txt", "r") as f: words = f.read().splitlines() for word in words: current_dict = root for letter in word: current_dict = current_dict.setdefault(letter.lower(), {}) current_dict["end"] = word.lower() return root ...