Tutorialspoint

Execute Python Online

A = []
dim = []
path = []

with open('maze.txt', 'r') as f:
  for line in f:
#    print(line)
    line_new = line.split(',')
#    print(line_new)
    line_new = [ int(x) for x in line_new ]
#    print(line_new)
    if len(line_new) == 2:
      dim=line_new
    else:
      A.append(line_new)

print(dim)
print("A =", A)
print("A[0] =", A[0]) 
print("A[1] =", A[1])     
print("A[1][2] =", A[1][2])
print("A[2][3] =", A[2][3])
print("A[0][-1] =", A[0][-1])


with open('path.txt', 'r') as f:
  for line in f:
    line_new = line.split(',')
    if len(line_new) == 2:
      line_new = [ int(x) for x in line_new ]
      start=line_new
    else:
      path = line_new

print(start)
print(path)

position = start
curr = start

for x in path:
#  print(x)
  if x == "UP":
#      print(A[curr[0]][curr[1]])
      position = [curr[0],curr[1]-1]
      curr = position
#      print(A[curr[0]][curr[1]])
  elif x == "DOWN":
      position = [curr[0],curr[1]+1]
      curr = position
  elif x == "LEFT":
      position = [curr[0]-1,curr[1]]
      curr = position
  elif x == "RIGHT":
      position = [curr[0]+1,curr[1]]
      curr = position
 
print(position)      

Execute Python Online

# Python program to illustrate while loop 
for i in range(15):
    a = int(input())
while a < 0:
        print("this is a negative number", a)
else:
    print("this is a positive number")

maison

# Hello World program in Python
    class jo 
       def _init_(self)
       self.jo= 'maison'
       self.bill= 45 
    
    
#print "Hello World!\n"

Execute Python Online

# Brute Force (Fake Coin) at least 1 


def CheckCoin():
    
    NoFakeCoin=0
    no=No
    i=1;
    
    while no != i-1:
        while i != j:
            if j <= i:
                j = 0
                if CoinW[i-1] < CoinW[j]:
                    NoFakeCoin +=1
                    j += 1
            elif CoinW[i-1] < CoinW[j]:
                NoFakeCoin += 1
                j += 1
                
def main():
    print("Enter the number of coin: ")
    x = input()
    print(x)
    No=int(x)
    size=0
    no=No 
    
    
    while no != 0 :
        print("Enter the  coin Weight 1(true)/ 0(fake)")
        CoinW[size]=int(input())
        size += 1
        no +=0
        
main()

mourya

import hashlib

def sha1(test):
    s = hashlib.sha1()
    s.update(test.encode('utf-8'))
    return s.hexdigest()
    
def getLastBlock(startBalances, pendingTransactions, blockSize):
    prevhash = "0000000000000000000000000000000000000000"
    bs = blockSize
    nonce = 28427
    bh1, pbh1, n1, bt1 = None, None, None, None
    i = 0
    j = i + bs - 1
    
    if j>=len(pendingTransactions) and i<len(pendingTransactions):
        j = len(pendingTransactions)-1
    
    while j < len(pendingTransactions):
        
        curr_trans = pendingTransactions[i:j+1]
        res = []
        
        
        for trans in curr_trans:
            t = get_str(trans)
            t = "[" + t + "]"
            res.append(t)
        
        curr = "[" + get_str(res) + "]"
        
        arr = []
        arr.append(prevhash)
        arr.append(nonce)
        arr.append(curr)
        
        tmp = get_str(arr)
        
        
        bh = sha1(tmp)
        print bh
        print tmp
        
        pbh1 = prevhash
        prevhash = bh
        
        i = j+1
        j = i + bs - 1
        
        if j>=len(pendingTransactions) and i<len(pendingTransactions):
            j = len(pendingTransactions)-1
        
        
    
        bh1, n1, bt1 = bh, nonce, curr
    
    temp = [bh1, n1, bt1]
    
    
    return get_str(temp)

def get_str(arr):
    res = ""
    
    for i in arr:
        if len(res)==0:
            res = str(i)
        else:
            res = res + ", " + str(i)
    
    return res
    


# print getLastBlock([5, 0, 0], [[0, 1, 5], [1, 2, 5]], 2)














Execute Python Online

from numpy import *
from math import *

class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __to_string__(self):
        print(" ( {0}, {1} ) ".format(self.x, self.y))

def createDataSet():
    dataSet = {}
    dataSet[Point(1.0, 1.1)] = 'A'
    dataSet[Point(1.0, 1.0)] = 'A'
    dataSet[Point(0.0, 0.0)] = 'B'
    dataSet[Point(0.0, 0.1)] = 'B'
    # Add another point
    return dataSet
    
def distance(current, point):
    return math.sqrt( math.pow((current.x - point.x), 2) + math.pow((current.y - point.y), 2) )
    

dico = createDataSet()

point = Point(0.0, 0.0)

var = []

for pt,label in dico.items():
    temp = [distance(point, pt), label]
    var.append(temp)

def order(res):
    #Tri 脿 bulles
    n=len(res)
    for i in reversed(range(1, n+1)):
        for j in range(2, i+1):
            if(res[j-2][0]>res[j-1][0]):
                temp = res[j-1]
                res[j-1] = res[j-2]
                res[j-2] = temp
    return res
        

def choix(liste, k):
    countA=0
    countB=0
    for i in range(3):
        if(liste[i][1]=='A'):
            countA += 1
        else:
            countB += 1
    if(countA>=countB):
        print('A')
    else:
        print('B')
            

def kNN(dataSet, k, toClassify):
    var = []

    for pt,label in dataSet.items():
        temp = [distance(toClassify, pt), label]
        var.append(temp)
    choix(order(var),k)
    

Execute Python Online

# Hello World program in Python
    javascript:;
print "fuck you world,fsociety"
clear

rebelcoder

# Hello World program in Python
    
print "Hello World!\n"

SIMONA LA ROSA PEDERNERA REGISTRO: 883684

# quadratic.py
#    A program that computes the real roots of a quadratic equation.
#    Illustrates use of the math library.
#    Note: This program crashes if the equation has no real roots.

import cmath  # Makes the math library available.

print("This program finds the real solutions to a quadratic")

a=-2
b=5
c=1
    
discRoot = cmath.sqrt( a * c)
root1 = (-b + discRoot) 
root2 = (-b - discRoot) 


print("The solutions are:", root1, root2 )

Execute Python Online

import random


class Player:
    global Deck

    def __init__(self, name):
        self.PlayerDeck = Deck
        random.shuffle(self.PlayerDeck)
        self.Hand = self.PlayerDeck[0:5]
        self.Wins = []
        self.Name = name

    def Reset(self):
        self.PlayerDeck = Deck
        random.shuffle(self.PlayerDeck)
        self.Hand = self.PlayerDeck[0:5]
        self.Wins = []

    def CheckWin(self):
        for i in range(len(self.Wins)):
            if len(self.Wins[i]) == 3:
                print(self.Name + " Wins!")
    
    def PrintHand(self):
        for i in self.Hand:
            print("[" + i.Type + ", " + str(i.Power) + ", " + i.Colour + "]")


class Card:
    def __init__(self, type, power, colour):
        self.Type = type
        self.Power = power
        self.Colour = colour


# Checks a card vs the players current winning cards and creates groups of potential round winning sets
def AddToWins(card, player):
    if len(player.Wins) == 0:
        player.Wins += [[card]]
        return
    for i in range(len(player.Wins)):
        for k in range(len(player.Wins[i])):
            if card[0] != player.Wins[i][k][0] and card[1] != player.Wins[i][k][1]:
                player.Wins[i] += [card]
            else:
                player.Wins += [[card]]
    player.CheckWin()


# Returns Winning Card or False if tie
def Battle(c1, c2):
    if c1.type == c2.type:
        if c1.power > c2.power:
            return c1
        if c1.power < c2.power:
            return c2
        if c1.power == c2.power:
            return False
    if (c1.type == "F" and c2.type == "S") or (c1.type == "W" and c2.type == "F") or (c1.type == "S" and c2.type == "W"):
        return c1
    else:
        return c2


Deck = [Card("F", 3, "Blue"), Card("F", 6, "Purple"),
        Card("F", 2, "Yellow"), Card("S", 3, "Orange"),
        Card("S", 2, "Red"), Card("S", 7, "Yellow"),
        Card("W", 5, "Blue"), Card("W", 2, "Green"),
        Card("W", 4, "Purple")]


player = Player("Nathan")
AI = Player("AI")

player.PrintHand()
AI.PrintHand()

1 2 3 4 5 6 7 ... 867 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.