0% found this document useful (0 votes)
4 views7 pages

Cs

The document contains a series of Python code snippets that demonstrate various programming concepts, including data collection, list manipulation, and mathematical computations. Key functionalities include student marks input, vowel counting, palindrome checking, Armstrong number identification, and price calculations with discounts. Each section illustrates different programming tasks, showcasing the use of loops, conditionals, and data structures.

Uploaded by

avinashvk230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Cs

The document contains a series of Python code snippets that demonstrate various programming concepts, including data collection, list manipulation, and mathematical computations. Key functionalities include student marks input, vowel counting, palindrome checking, Armstrong number identification, and price calculations with discounts. Each section illustrates different programming tasks, showcasing the use of loops, conditionals, and data structures.

Uploaded by

avinashvk230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#23 #22

d={}

while True:

n=input('Enter student name: ')

m=int(input('Enter marks: '))

d[n]=m

e=input('Enter another(y/n): ')

if e=='n':

break

print('The students whose name contains a: ')

for i in d:

if 'a' in i:

print(i,':',d[i])

s=input('Enter a sentence')

l=s.lower()

sl=l.split()

d={}

for i in sl:

if i not in d:

d[i]=sl.count(i)

print(d)

#21

d={}

while True:

i=input('Enter an item: ')

p=int(input('Enter its price: '))

d[i]=p

e=input('Enter another(y/n): ')

if e=='n':

break

A=input('Enter an item to search its price: ')


for i in d:

if i==A:

print(i,':',d[i])

T=()

i=5

while i>0:

t=eval(input('Enter a tuple of 3 integers: '))

T+=(t,)

i-=1

k=1

for i in T:

s=sum(i)

a=s/3

print('The total mark of stundent',k,' is',s,'and the average is',a)

k+=1

#19

L=eval(input('Enter a list of integers: '))

L1=[]

L2=[]

for i in L:

if i%2==0:

L1+=[i]

else:

L2+=[i]

print('Even list: ',L1)

print('Odd list: ',L2)

#18

L=eval(input('Enter a list of integers: '))

for i in range(len(L)):

if L[i]%2==0:
L[i]*=5

else:

L[i]+=10

print('The new list is :',L)

#longest word program

x=eval(input("enter a list of words"))

y=0

for i in x:

if len(i)>y:

y=len(i)

z=i

else:

pass

print("the longest word is:",z)

#count the number of vowels

x=input("enter a word:")

c=0

for i in x :

if i in 'aeiou'or i in 'AEIOU':

c+=1

print("number of vowels is",c)

#check palindrome or not

x=input("enter a word:")

y=x[::1]

if x==y:

print('word is palindrome')

else:

print("word is palindrome")

#amstrong number

for i in range(1,501):

x=i%10
y=i//10

z=y%10

d=y//10

a=d%10

b=d//10

s=x**3+z**3+a**3

if s==i:

print(i)

#reverse the number

x=int(input("enter a number :"))

r=0

while x>0:

dig=x%10

r=r*10+dig

x=x//10

print('revesre of a numberis',r)

#multiplication table

x=int(input('enter a number:'))

for i in range (1,11):

print(i,'x',x,'=',x*i)

#factor program

x=int(input("enter a number:"))

print('Factors are:',end='',)

for i in range (1,x+1):

if x%i==0:

print(i,end=',')

#checking for prime number

x=int(input("enter a number:"))

for i in range (2,x):

if x%2==0:

print('number is a composite')
break

else:

print('number is prime')

#sum ofrange of values

s=0

for i in range(100,1001):

if i%3==0 or i%5==0:

s+=i

print(s)

#finding the result based on percentage

x=int(input("enter the percentage:"))

if x>75:

print('your result is first class')

elif 60<x<75:

print('your result is second class')

elif 40<x<60:

print('your result is pass class')

else:

print('you are failed')

x=int(input("enter the number one:"))

y=int(input("engter the number two:"))

z=int(input("enter the number three:"))

if x>y and x>z:

print('x is the greatest number',x)

elif y>x and y>z:

print('y is the greatest number',y)

else:

print("z is the greatest number",z)

#claculathig the discounted price

x=int(input("enter the sale:"))


if x<1000:

print('no discont')

print('the total price is ',x,)

if 1000<=x<=5000:

print('5% discount')

y=5*x/100

print('the discounted price is',y)

z=x-y

print(' the total prize is',z)

if x>=5000:

print('10% discount')

y=10*x/100

print("the discounted prize is",y)

z=x-y

print('the total prize is',z)

#finding the factors of a number

x=int(input('enter a number:'))

print('factors are :',end='')

for i in range (1,x+1):

if x%i==0:

print(i,end=',')

#phone number program

n=input('enter a phone number:')

valid=True

if len(n)!=10:

vlaid=False

elif not(n[0:3].isdigit()):

vlaid=False

elif n[3]!='_':

vlaid=False
elif (n[3:].isdigit()):

valid=False

if valid==True:

print(n,'is valid')

else:

print(n,'is not valid')

#highest price

d={}

while True:

i=input('enter product name:')

p=float(input('enter product name'))

d[i]=p

e=input('enter another (y/n):')

if e=='n':

break

v=list(d.values())

M=max(v)

print('highest price:',M)

print('the product that costd',M)

for i in d:

if d[i]==M:

print(i)

You might also like