0% found this document useful (0 votes)
28 views1 page

1.palindrome: "It Is A Palindrome" "It Is Not A Palindrome"

The document contains 5 code snippets that demonstrate different Python programming concepts: 1) checking if a string is a palindrome, 2) generating lists with conditional logic, 3) calculating distance between two points, 4) printing star patterns, and 5) converting decimals to binaries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

1.palindrome: "It Is A Palindrome" "It Is Not A Palindrome"

The document contains 5 code snippets that demonstrate different Python programming concepts: 1) checking if a string is a palindrome, 2) generating lists with conditional logic, 3) calculating distance between two points, 4) printing star patterns, and 5) converting decimals to binaries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Palindrome
In [ ]: t=int(input())

while t>=1:

s=str(input())

l=len(s)//2

cnt=0

for i in range(l):

if s[i].lower()==s[len(s)-i-1].lower():

cnt+=1

if cnt==l:

print("It is a palindrome")

else:

print("It is not a palindrome")

2.Ifs and For's


In [ ]: t=int(input())

while t>=1:

t-=1

n=int(input())

l=[]

for i in range(n):

if i==0:

l.append(3)

elif i%2==0:

l.append(2*i)

else:

l.append(i*i)

print(*l)

3.Distance B/W Two Points


In [ ]: t=int(input())

while t>=1:

t-=1

x1,y1,x2,y2=map(int,input().split())

d1=x1-x2

d2=y1-y2

ed=pow((d1*d1)+(d2*d2),0.5)

format_ans="{:.2f}".format(ed)

print(format_ans)

4.Stars In Our Pattern


In [ ]: t=int(input())

while t>=1:

t-=1

n=int(input())

i=n

while i!=0:

j=0

while j<i:

if (j+1)%5==0:

print("#",end="")

else:

print("*",end="")

j+=1

i-=1

print()

5.Convert Decimal To Binary


In [ ]: def DecimalToBinary(num):

if num >= 1:

DecimalToBinary(num // 2)

print(num % 2, end='')

t=int(input())

while t>=1:

t-=1

n=int(input())

DecimalToBinary(n)

print()

You might also like