Python Record
Python Record
"""write5 a python program that asks user for a weight in kilo greams and converts it in to
pounds.there are 2.2 pounds in kilo gram"""
# weight in kilo gram is wkg
wkg=float(input("enter the weight in kilo grams"))
### weight in pound is wp
wp=wkg*2.2
#t output statement
print(wp)
output:
enter the weight in kilo grams67
147.4
2. # write a python program that asks the user to enter three numbers (use seperate statements).
create variables called total and average that holds sum and average of three numbers and print out
the values of total and average .
total=fv+sv+tv
average=total/3
output:
3. # write a python program that asks the user for loop to print numbers 8,11,14,17,20,......83,86,89
i=8
# using while loop
while(i<=90):
print(i,end=",")
#increment pf value by 3
i=i+3
output:
8,11,14,17,20,23,26,29,32,35,38,41,44,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,
4. # write a program that asks the user their name and how many times to print it.the program
should print out users name the specified no.of.times
n=input("enter name:")
for i in range(0,t):
print(n)
output:
enter name:sravan
sravan
sravan
sravan
sravan
sravan
5. # use a for loop to print a triangle with the stars.allow user to secify what is the height of triangle
# height of triangle is h
for i in range(1,h+1):
print("*"*i,end="\n")
output:
**
***
****
*****
6. # generate a random number between 1 to 10. ask the user to guess the nuber and print
appropriate meassage
import random
n= random.randint(1, 10)
# conditional statements
if(n==g):
else:
#output staements
output:
7. # write a program that asks for two numbers and prints close if the numbers are within 0.001 of
each other and not close other wise
#conditional statements
if((a-b)<=0.001)or((b-a)<=0.001):
print("close")
else:
print("not close")
output:
close
#conditional staements
for letter in n:
if letter in "aeiouAEIOU":
v=1
if(v==1):
else:
output:
9. # write a program that asks the user to enter two strings of the same length. The program should
check to see ,if the strings are of the same length. If they are not, the program should print an
appropriate message and exit. If they are of the same length, the program alternate the characters
of two strings.
n=0
if(len(s1)==len(s2)):
print("same lenght")
n=1
else:
new=" "
if(n==1):
for i in range(0,len(s1)):
new=new+s1[i]+s2[i]
print(new)
output:
10. #Write a program that asks the user for a large integer and insert commas into it according to
the standard American convention for commas in large numbers. For instance, if the user enters
1000000, the output should be 1,000,000.
def place_value(number):
return ("{:,}".format(number))
print(place_value(num))
output:
10,000,000,000,000
new=" "
a="-*+/"
for i in range(0,len(eq)-1):
new=new+eq[i]+"*"+eq[i+1]
else:
if(eq[i+1] in a):
new=new+eq[i+1]
else:
new=new
print(new)
output:
2*x+3*y
lst=[]
even_count=0
for i in range(0,20):
n=random.randint(1,100)
lst.append(n)
print(lst)
for i in range(100,1,-1):
if i in lst :
larger=i
break
for i in range(larger-1,1,-1):
if i in lst :
slarger=i
break
for i in range(1,100):
if i in lst:
smallest=i
break
for i in range(smallest+1,100):
if i in lst:
ssmallest=i
break
if(val%2==0):
even_count+=1
output:
[1, 66, 29, 97, 18, 89, 98, 1, 71, 16, 67, 38, 56, 56, 25, 11, 98, 99, 11, 9]
flist=[]
for i in range(1,n+1):
if(n%i==0):
flist.append(i)
print(flist)
output:
list=[]
for i in range(0,100):
x=random.randint(0,1)
list.append(x)
print(list)
c=0
max_count=0
for i in list:
if i==0:
c=c+1
else:
if c>max_count:
max_count=c
else:
c=0
print("maximum consective zeros count is:",max_count)
output:
[0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
list=[]
newlist=[]
list.append(n)
for i in n:
if i not in newlist:
newlist.append(i)
print(newlist)
output:
[2, 3, 4, 5, 6, 7, 8]
print("1.inches\n2.yard\n3.mile\n4.millimeters\n5.centi meters\n6.meters")
if(c<=6):
if(c==1):
l_inch=l_feet*12
print(l_inch)
if(c==2):
l_yard=l_feet*(1/3)
print(l_yard)
if(c==3):
l_mile=l_feet*0.000189394
print(l_mile)
if(c==4):
l_mm=l_feet*304.8
print(l_mm)
if(c==5):
l_cm=l_feet*30.48
print(l_cm)
if(c==6):
l_m=l_feet*0.3048
print(l_m)
else:
output:
1.inches
2.yard
3.mile
4.millimeters
5.centi meters
6.meters
60
sum=0
while(n>0):
sum=sum+n%10
n=n//10
return sum
output:
def frist_diff(s1,s2):
f=0
n=0
if(len(s1)>=len(s2)):
n=len(s2)
else:
n=len(s1)
for i in range(0,n):
if(s1[i]!=s2[i]):
f=1
return i
break
if(f==0):
return -1
output:
factors=0
for i in range(1,n+1):
if(n%i==0):
factors+=1
return factors
output:
for i in range(0,len(l)-1):
if(l[i]>l[i+1]):
break
else:
continue
if(i==len(l)-2):
return True
else:
return False
list=[1,2,2,3,3,4]
print(is_sorted(list))
output:
True
21.
def root(n,r):
a=0
if(r==0):
r=2
a=pow(n,1/r)
else:
a=pow(n,1/r)
return a
print(root(n,r))
output;
1.9441612972396656
f=0
if(n%i==0):
f=1
break
if(f==0):
return n
def count_prime(N):
i=2
lst=[]
c=0
while(c<=N):
if(prime(i)==i):
lst.append(i)
c+=1
return lst
print(count_prime(N))
output:
23. # case a
a=[]
b=[]
for i in range(0,n1):
a.append(n)
for i in range(0,n2):
b.append(n)
new=a+b
print(new)
output:
t=list(itertools.permutations(s,len(s)))
for i in range(0,len(t)):
print("".join(t[i]),end=" ")
output:
book boko book boko bkoo bkoo obok obko oobk ookb okbo okob obok obko oobk ookb okbo okob
kboo kboo kobo koob kobo koob
26. f=open("gmail.txt","r")
b=f.readlines()
for i in range(0,len(b)):
print(b[i],end=";")
output:
sravan2207@gmail.com
;sujayraghavendra@gmail.com
;rohit679@gmail.com