Number of regions python assignment expert

Number of moves:

you are given a nxn square chessboard with one bishop and k number of obstacles placed on it. A bishop can go to different places in a single move. find the total no.of places that are possible for the bishop in a single move. Each square is referenced by a type describing the row, R, and column, C, where the square is located.

explanation: given N=6 K=2

bishop position 5 2

obstacle positions [2 2], [1 5]

the bishop can move in so o/p is 6

I/p:

6 2

5 2

2 2

1 6

O/p:

6

I/p:

6 4

3 3

1 3

3 1

5 1

1 5

O/p: 7

[n, k] = input[].split[' ']
n = int[n]
k = int[k]
board = []
for i in range[n]:
    for j in range[n]:
        board.append[[i+1, j+1]]
lst = []
obst = []
bp = input[].split[' ']
bp = [int[bp[0]], int[bp[1]]]
for i in range[k]:
    obst = input[].split[' ']
    lst.append[[int[obst[0]], int[obst[1]]]]
count = 0
for shift in [[1, 1], [-1, 1], [1, -1], [-1, -1]]:
    new_pos = [bp[0] + shift[0], bp[1] + shift[1]]
    while new_pos in board and new_pos not in obst:
        count += 1
        new_pos = [new_pos[0] + shift[0], new_pos[1] + shift[1]]
print[count]

first place

the ouput should be single line containing the ones place of positive integer

input 1:25

ouput:5

input 2:200

output:0

a = int[input['enter a number']]
b = a % 10
print[b]

Learn more about our help with Assignments: Python

Last update on August 19 2022 21:50:48 [UTC/GMT +8 hours]

Python Basic - 1: Exercise-54 with Solution

if you draw a straight line on a plane, the plane is divided into two regions. For example, if you pull two straight lines in parallel, you get three areas, and if you draw vertically one to the other you get 4 areas.
Write a Python program to create maximum number of regions obtained by drawing n given straight lines.

Input:
[1 ≤ n ≤ 10,000]
Input number of straight lines [o to exit]:
5
Number of regions:
16

Sample Solution:

Python Code:

while True:
    print["Input number of straight lines [o to exit]: "]
    n=int[input[]]
    if n=4, Goldbach number] from the user and create a combinations that express the given number as a sum of two prime numbers. Print the number of combinations.
Next: Write a Python program to test AB and CD are orthogonal or not.

Python: Tips of the Day

Union Of Collections:

To get a distinct combined set of two sets.

a = {1,2,3}
b = {3,4,5}
c = a.union[b]

import numpy as np
 print['']
 print["Enter two numbers, low then high."]
 l = int[input["low = "]]
 h = int[input["high = "]]


 def binarySearch [arr, l, r, num]:
 if r >= l:
 mid = l + [r - l] // 2

print["Is your number Less than, Greater than, or Equal to {0}?".format[arr[mid]]]
 while True:
 x = str[input["Type 'L', 'G' or 'E':"]]
 if x in ['L', 'G', 'E', 'l', 'g', 'e']:
 break

print['']
 if x == 'E' or x == 'e':
 num = num + 1
 if num == 1:
 print["I found your number in 1 guess."]
 else :
 print["Your number is {0}. I found it in {1} guesses.".format[arr[mid], num]]
 elif x == 'L' or x == 'l':
 num = num + 1
 return binarySearch[arr, l, mid-1, num]
 else:
 num = num + 1
 return binarySearch[arr, mid + 1, r, num]
 else:
 print["Your answers have not been consistent."]

while l>h:
 print['']
 print["Please enter the smaller followed by the larger number."]
 l = int[input["low = "]]
 h = int[input["high = "]]

print['']
 print["Think of a number in the range {0} to {1}.".format[l, h]]

print['']
 if l == h:
 print["Your number is {0}. I found it in 0 guesses.".format[l]]

else :
 arr = np.arange[l+1, h]
 binarySearch[arr, 0, len[arr]-1, 0]

Chủ Đề