Notes
Notes - notes.io |
Write a program to print Christmas Tree Pattern
Code:
level = int(input("Enter level of tree: "))
space = 100
pattern = [(('* '*(i+j+1)).center(space)) for i in range(0, level*2 , 2) for j in range(8) ]
print('n'.join(pattern + [('* '*3).center(space) for i in range(8) ]))
Practical 2
In the world of Dragon Ball, Goku has been the greatest rival of Vegeta.
Code:
while True:
try:
n, c = int(input()), 0
while n != 0:
n = n&(n-1)
c += 1
print(c)
except EOFError:
Break
Practical 3
Mr. Vincent works in a doormat manufacturing company. One day, he designed a
Code:
n, m = [int(i) for i in input().split()]
pattern = [(('.|.'*(2*i + 1)).center(m, '-')) for i in range(n//2)]
print('n'.join(pattern + ['WELCOME'.center(m, '-')] + pattern[::-1]))
Practical 4
For this challenge, you are given two complex numbers, and you have to print
Code:
from math import sqrt
class Complex:
def __init__(self, real = 0.00, imag = 0.00):
self.real = real
self.imag = imag
def __add__(self, other):
real = self.real + other.real
imag = self.imag + other.imag
return repr(Complex(real, imag))
def __sub__(self, other):
real = self.real - other.real
imag = self.imag - other.imag
return repr(Complex(real, imag))
def __mul__(self, other):
real = self.real * other.real - self.imag * other.imag
imag = self.real * other.imag + self.imag * other.real
return repr(Complex(real, imag))
def __truediv__(self, other):
real = (self.real * other.real + self.imag * other.imag) / (other.real**2 + other.imag**2)
imag = (self.imag * other.real - self.real * other.imag) / (other.real**2 + other.imag**2)
return repr(Complex(real, imag))
def mod(self):
real = sqrt(self.real**2 + self.imag**2)
return repr(Complex(real))
def __repr__(self):
if self.imag < 0:
return "{:.2f}{:.2f}i".format(self.real, self.imag)
else:
return "{:.2f}+{:.2f}i".format(self.real, self.imag)
a, b = [eval(x) for x in input().split()], [eval(x) for x in input().split()]
c, d = Complex(a[0], a[1]), Complex(b[0], b[1])
print(c+d)
print(c-d)
print(c*d)
print(c/d)
print(c.mod())
print(d.mod())
Practical 5
You are given two strings S and T of the same length N. Your task is to
Code:
n = int(input())
s = input()
t = input()
for i in range(n-1):
if s[i:n-1] == t[0:n-1-i]:
break
print(i)
Practical 6
There is a group of people in a room. Everyone has a number written on their
Code:
n = int(input())
lst = sum([int(data) for data in input().split()])
lst1 = sum([int(data) for data in input().split()])
lst2 = sum([int(data) for data in input().split()])
lst3 = sum([int(data) for data in input().split()])
print(lst - lst1)
print(lst1 - lst2)
print(lst2 - lst3)
Practical 7
Microsoft has come to hire interns from your college. N students got
Code:
n = int(input())
f, m = [], []
for i in range(n):
a, b = [int(data) for data in input().split()]
if a == 0:
f.append(b)
else:
m.append(b)
lst = list(reversed(sorted(f))) + list(reversed(sorted(m)))
print(" ".join(map(str, lst)))
Practical 8
Given an integer N. Find out the PermutationSum where PermutationSum for
Code:
t = int(input())
for n in range(t):
n = int(input())
if n == 1:
print(1)
else:
print(((n*n)//2) - 1)
Practical 9
Indian army is going to do a surprise attack on one of its enemy countries.
Code:
msg = input()
key = int(input())
s = ''
for _ in msg:
if ord(_) >= 48 and ord(_) <= 57:
temp = ord(_) + key
if temp > 57:
s += chr(47 + (temp % 57))
else:
s += chr(temp)
elif ord(_) >= 97 and ord(_) <= 122:
temp = ord(_) + key
if temp > 122:
s += chr(96 + (temp % 122))
else:
s += chr(temp)
elif ord(_) >= 65 and ord(_) <= 90:
temp = ord(_) + key
if temp > 90:
s += chr(64 + (temp % 90))
else:
s += chr(temp)
else:
s += _
print(s)
Practical 10
Dhananjay has recently learned about ASCII values.He is very fond of
Code:
t = int(input())
prime_lst=[67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113]
while t:
n = int(input())
s = input()
c = ''
for i in s:
lst = prime_lst.copy()
lst.insert(0, ord(i))
lst.sort()
j = lst.index(ord(i))
if j != 0 and j != (len(lst)-1) and abs(ord(i)-lst[j-1]) <= abs(ord(i)-lst[j+1]):
c += chr(lst[j-1])
elif j != (len(lst)-1):
c += chr(lst[j+1])
elif j == (len(lst)-1):
c += chr(lst[j-1])
print(c)
t -= 1
Practical 11
You are in a battle field and your enemy has an army of N soldiers. Each
Code:
try:
t = int(input())
for i in range(t):
n = int(input())
c = 0
max_sum=0
lst = [int(x) for x in input().split()]
for i in lst:
if(i < 0):
c += 1
else:
max_sum += i
if(c == n):
min_no = min(lst)
while(min_no > 1):
min_no /= 2
if(min_no == 1):
print("Yes")
else:
print("No")
else:
while(max_sum > 1):
max_sum /= 2
if(max_sum == 1):
print("Yes”)
else:
print("No")
except EOFError as e:
print(end="")
Practical 12
Little Bear has received a home assignment to find the sum of all digits in
Code:
t = int(input())
while(t):
m = int(input())
sums, ans = 0, 0
while(m):
n = [int(x) for x in input().split( )]
sums += (n[0]*n[1])
m -= 1
while(len(str(sums)) !=1 ):
for i in str(sums):
ans += int(i)
sums = ans
ans = 0
print(sums)
t -=1
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team