0% found this document useful (0 votes)
3 views

python

The document contains Python code snippets for various tasks including creating lists and tuples, checking for palindromes, majestic numbers, and managing a dictionary of students and friends with their respective details. It demonstrates user input handling, conditional statements, and basic data structure operations. The code also includes functionality for adding, deleting, and modifying entries in a dictionary.

Uploaded by

Zaptoz Pad
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

python

The document contains Python code snippets for various tasks including creating lists and tuples, checking for palindromes, majestic numbers, and managing a dictionary of students and friends with their respective details. It demonstrates user input handling, conditional statements, and basic data structure operations. The code also includes functionality for adding, deleting, and modifying entries in a dictionary.

Uploaded by

Zaptoz Pad
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

n=int(input("enter no of elemets req in list"))

l=[]
for i in range(n):
ele=int(input("enter element"))
l.append(ele)
print("List is " ,l)

n=int(input("enter no of elemets req in tuple"))


T=()
for i in range(n):
t=input("enter elelemennts")
T=T+(t,)
print(T)

n="anand"
l=len(n)
for i in range(l+1):
for j in range(0,i):
print(n[j],end="")
print()

#checking for palindrome n=int(input("


enter any number"))
m=n
rev=0 while(n>0):
rem=n%10
rev=rev*10+rem n=n//10
print("
'reverse is",.rev)
if rev==m:
print(m," is palindrome")
else:
print(m,
,"is not a palindrome")

#checking for majestic number n=int(input(" enter any number"))


m=1
S=0
while(n>0):
r-n%10
m=m*r#multiplication of digits s=s+r#sum of digits n=n//10
print(" multiplication of digit is", m)
print(" sum of digit is",s)
if (s==m):
print(" majestic no")
else:
print(" non majestic number")

d={}
r{}
n=int(input("
enter number of students you want to enter in dictionary"))
for i in range (n):
s=input(" enter name of student") p=int(input("
enter percentage of student "))
if p>=90 : g="A
elif p>=80 :
g="B"
elif p>=70 :
g=" C"
elif p>=60 :
g="D"
else:
g=" Fail" d[s]=p
r[s]=g
print(d)
print(r)
for i in d :
print(i," ", d[i]," ",r[i])

d= |)
n= int(input ("no of friends whoose data you are entering")) for i in range (n):
f=input(" enter name of friend:")
ph = int(input ("
enter phore no
"))
d[f]= ph
print (d) for i in d: print (i,
, d[il)
print ("for entering a new key value pair in dictionary")
N= input ("
enter name:")
Ph = int(input ("
enter number :"))
d[N] =Ph
print (d)
print("for deleting a particular friend from the list")
N = input ("
'enter name :")
del dINJ print (d)
print (" for modifying the phone number of a friend ")
F = input("
Phi = int input ('ame of friend"
enter new number :'))
d[F] = Phi
print (d)
print("to check if a friend exist in a list or not")
F = input (" enter name of friend '")
printd. get (F))
# printing dictionary in sorted order
print(sorted(d))
print(sorted(d.values))

You might also like