Codechef Solutions — Beginner Level (Python) PART 3

Key computer Education
4 min readFeb 26, 2022

--

Gross Salary Problem Code: FLOW011

In a company an emplopyee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of base salary and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic salary. If the Employee’s salary is input, write a program to find his gross salary.

n = int(input())for i in range(n):
sal = int(input())
if sal< 1500:
hra = 0.10 * sal
da = 0.90 * sal
else:
hra = 500
da = 0.98 * sal
print(sal+hra+da)

The Smallest Pair

You are given a sequence a1, a2, …, aN. Find the smallest possible value of ai + aj, where 1 ≤ i < jN.

# cook your dish here
n1 = int(input())
for i in range(n1):
n = int(input())
L1= list(map(int, input().split()))
L1.sort()
print(L1[0]+L1[1])

Lapindromes

Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match.
Your task is simple. Given a string, you need to tell if it is a lapindrome.

n = int(input())for i in range(n):
str1 = input()
lstr = str1[:len(str1)//2]
ustr = str1[(len(str1)+1)//2: ]
if sorted(lstr)== sorted(ustr):
print("YES")
else:
print("NO")

Grade The Steel

A certain type of steel is graded according to the following conditions.

  1. Hardness of the steel must be greater than 50
  2. Carbon content of the steel must be less than 0.7
  3. Tensile strength must be greater than 5600

The grades awarded are as follows:

  • Grade is 10 if all three conditions are met
  • Grade is 9 if conditions (1) and (2) are met
  • Grade is 8 if conditions (2) and (3) are met
  • Grade is 7 if conditions (1) and (3) are met
  • Grade is 6 if only one condition is met
  • Grade is 5 if none of the three conditions are met
n=int(input())for i in range(n):
h,c,t = tuple(map(float,input().split()))

if h > 50 and c< 0.7 and t > 5600:
print(10)
elif h > 50 and c<0.7 :
print(9)
elif c<0.7 and t > 5600:
print(8)
elif h > 50 and t > 5600:
print(7)
elif h > 50 or c<0.7 or t > 5600:
print(6)
else:
print(5)

Sums in a Triangle Problem Code: SUMTRIAN

Given an integer NN, let us consider a triangle of numbers of NN lines in which a number a11a11 appears in the first line, two numbers a21a21 and a22a22 appear in the second line, three numbers a31a31, a32a32 and a33a33 appear in the third line, etc. In general, ii numbers ai1,ai2…aiiai1,ai2…aii appear in the ithith line for all 1≤i≤N1≤i≤N. Develop a program that will compute the largest of the sums of numbers that appear on the paths starting from the top towards the base, so that:

T = int(input())
for i in range(T):
l = []
m = int(input())
for j in range(m):
n = list(map(int, input().split()))
l.append(n)

for j in range(m - 2, -1, -1):
for k in range(0, j+1):
l[j][k] += max(l[j+1][k], l[j+1][k+1])
print(l[0][0])

SHOPCHANGE

Chef went shopping and bought items worth XX rupees (1≤X≤1001≤X≤100). Unfortunately, Chef only has a single 100100 rupees note.

Since Chef is weak at maths, can you help Chef in calculating what money he should get back after paying 100100 rupees for those items?

# cook your dish here
n = int(input())
for i in range(n):
num = int(input())
print(100-num)

Chef and NextGen Problem Code: HELIUM

Chef is currently working for a secret research group called NEXTGEN. While the rest of the world is still in search of a way to utilize Helium-3 as a fuel, NEXTGEN scientists have been able to achieve 2 major milestones:

  1. Finding a way to make a nuclear reactor that will be able to utilize Helium-3 as a fuel
  2. Obtaining every bit of Helium-3 from the moon’s surface
n = int(input())for i in range(n):
A,B, X, Y = tuple(map(int, input().split()))
if X * Y >= A * B:
print("Yes")
else:
print("No")

Count the Notebooks Problem Code: NOTEBOOK

You know that 11 kg of pulp can be used to make 1000 pages and 11 notebook consists of 100 pages.

Suppose a notebook factory receives N kg of pulp, how many notebooks can be made from that?

n = int(input())
for i in range(n):
kg = int(input())
pages = kg *1000
books = pages// 100
print(books)

--

--

Key computer Education

keykoders.wordpress.com Opens up the Mind Programming for Beginner | Coding Tutorial | Free Programs | Free Projects