Skip to content

Commit c364908

Browse files
authored
Add files via upload
0 parents  commit c364908

File tree

44 files changed

+933
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+933
-0
lines changed

Assignment 26.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
2+
# between 2000 and 3200 (both included).
3+
# The numbers obtained should be printed in a commaseparated sequence on a single line.
4+
5+
for i in range (2000,3201,1):
6+
if (i%7==0 and i%5!=0):
7+
print(i,end=",")

Assignment 27.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write a program which can compute the factorial of a given numbers.
2+
# The results should be printed in a comma-separated sequence on a single line.
3+
4+
def fact(n):
5+
if (n==1 or n==0):
6+
return 1
7+
else:
8+
return n*fact(n-1)
9+
10+
x = int(input("enter the value of x:"))
11+
12+
for i in range (0,x+1,1):
13+
y=fact(i)
14+
if i==x:
15+
print(y,end=".")
16+
else:
17+
print(y,end=",")
18+
print(" ")

Assignment 28.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Write a program that accepts a comma separated sequence of words as input
2+
# and prints the words in a comma-separated sequence after sorting them alphabetically.
3+
4+
def lts(x):
5+
str=" "
6+
return str.join(x)
7+
8+
words=input("enter the words separated by comma:")
9+
10+
low=words.split(",")
11+
12+
a=list(low)
13+
a.sort()
14+
b=lts(a)
15+
print(b)

Assignment 29.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Write a program that accepts sequence of lines as input and
2+
# prints the lines after making all characters in the sentence capitalized.
3+
4+
def lts(x):
5+
str=""
6+
for ele in x:
7+
str += ele
8+
return str
9+
10+
line=input("enter the line:")
11+
12+
a=list(line)
13+
b=[]
14+
15+
for i in range (0,len(a),1):
16+
b += str(a[i]).capitalize()
17+
c=lts(b)
18+
19+
print(c)
20+

Assignment 30.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write a program that accepts a sequence of whitespace separated words as input
2+
# and prints the words after removing all duplicate words and sorting them alphanumerically.
3+
4+
5+
def lts(x):
6+
str=" "
7+
return str.join(x)
8+
9+
text= input("Please enter any text:")
10+
lat=text.lower()
11+
words=lat.split()
12+
13+
lwdw=list(set(words))
14+
lwdw.sort()
15+
ltsc=lts(lwdw)
16+
print(ltsc)

Assignment 31.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Write a program which accepts a sequence of comma separated 4-digit binary numbers as its input.
2+
# Then check whether they are divisible by 5 or not.
3+
# The numbers that are divisible by 5 are to be printed in a comma separated sequence.
4+
5+
6+
binary=input("enter the comma separated binary digits:")
7+
bdl=binary.split(",")
8+
value = []
9+
for digits in bdl:
10+
num = int(digits,2)
11+
print (num)
12+
if (num%5==0):
13+
value.append(digits)
14+
15+
print (",".join(value))

Assignment 32.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.
2+
# The numbers obtained should be printed in a comma-separated sequence on a single line.
3+
4+
m=int(input("enter the intial value:"))
5+
n=int(input("enter the final value:"))
6+
a=[]
7+
8+
for i in range(m,n+1,1):
9+
num=i
10+
condition=True
11+
while(num!=0):
12+
digit=num%10
13+
num=num//10
14+
15+
if(digit%2!=0):
16+
condition=False
17+
break
18+
if(condition):
19+
a.append(i)
20+
print(a)

Assignment 33.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Write a program that accepts a sentence and calculate the number of letters and digits.
2+
3+
text=input("enter the text:")
4+
a=tuple(text)
5+
print(a)
6+
b=len(a)
7+
n=0
8+
m=0
9+
for i in range (0,b,1):
10+
if (a[i]==' '):
11+
continue
12+
elif (a[i]=='.'):
13+
continue
14+
elif (a[i]=='0' or a[i]=='1' or a[i]=='2' or a[i]=='3' or a[i]=='4' or a[i]=='5' or a[i]=='6' or a[i]=='7' or a[i]=='8' or a[i]=='9'):
15+
continue
16+
elif (a[i]==',' or a[i]=='<' or a[i]=='>' or a[i]=='/' or a[i]=='?' or a[i]==':' or a[i]==';' or a[i]=='{' or a[i]=='}' or a[i]=='[' or a[i]==']' or a[i]=='\\' or a[i]=='|' or a[i]=='"' or a[i]=='+' or a[i]=='`' or a[i]=='~' or a[i]=='!' or a[i]=='@' or a[i]=='#' or a[i]=='$' or a[i]=='%' or a[i]=='^' or a[i]=='&' or a[i]=='*' or a[i]=='(' or a[i]==')' or a[i]=='-' or a[i]=='_' or a[i]=='=' ):
17+
continue
18+
else:
19+
n=n+1
20+
print(n,"is the number of letters in a given text.")
21+
for j in range (0,b,1):
22+
if (a[j]==' '):
23+
continue
24+
elif (a[j]=='.'):
25+
continue
26+
elif (a[j]=='0' or a[j]=='1' or a[j]=='2' or a[j]=='3' or a[j]=='4' or a[j]=='5' or a[j]=='6' or a[j]=='7' or a[j]=='8' or a[j]=='9'):
27+
m=m+1
28+
else:
29+
continue
30+
print(m,"is the number of digits in a given text.")
31+
32+
print("the program was executed.")

Assignment 34.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Q.no:9. A website requires the users to input username and password to register.
2+
#Write a program to check the validity of password input by users.
3+
#Following are the criteria for checking the password:
4+
#At least 1 letter between [a-z]
5+
#At least 1 number between [0-9]
6+
#At least 1 letter between [A-Z]
7+
#At least 1 character from [$#@]
8+
#Minimum length of transaction password: 6
9+
#your program should accept a sequence of comma separated passwords and
10+
#will check them according to the above criteria. Passwords that match the
11+
#criteria are to be printed, each separated by a comma.
12+
13+
import re
14+
def word():
15+
password=input("enter the password:")
16+
return password
17+
18+
password=word()
19+
keys=password.split(",")
20+
length=len(keys)
21+
accepted_pass=[]
22+
for ele in keys:
23+
if (length<6) and (length>12):
24+
continue
25+
elif not re.search("([a-z])+",ele):
26+
continue
27+
elif not re.search("([A-Z])+", ele):
28+
continue
29+
elif not re.search("([0-9])+", ele):
30+
continue
31+
elif not re.search("([!@$%^&])+", ele):
32+
continue
33+
else:
34+
accepted_pass.append(ele)

Assignment 35.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#You are required to write a program to sort the (name, age, height) tuples by ascending order
2+
# where name is string, age and height are numbers. The tuples are input by console. The sort criteria is:
3+
# 1: Sort based on name;
4+
# 2: Then sort based on age;
5+
# 3: Then sort by score.
6+
# The priority is that name > age > score.
7+
# If the following tuples are given as input to the program:
8+
# Tom,19,80
9+
# John,20,90
10+
# Jony,17,91
11+
# Jony,17,93
12+
# Json,21,85
13+
# Then, the output of the program should be:
14+
# [('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'),('Tom', '19', '80')]
15+
16+
from numpy import sort
17+
18+
19+
det=[('John', '90','20'), ('17','Jony', '91'), ('Jony', '17', '93'), ('Json', '21', '85'),('Tom', '19', '80')]
20+
sorted(det)
21+
for i in det:
22+
j=list(i)
23+
sorted(j)
24+
print (j)
25+
# for j in i:
26+
# print(j)
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+

Assignment 36.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# write a program to compute the frequency of the words from the input
2+
3+
4+
line =input("Enter Text:")
5+
l=line.split()
6+
d = {}
7+
for i in l:
8+
if i not in d.keys():
9+
d[i]=0
10+
d[i]=d[i]+1
11+
print(d)

Assignment 37.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Define a function that can accept two strings as input and
2+
# print the string with maximum length in consol
3+
4+
def leng(y):
5+
return max(y,key=len)
6+
x=input("Enter two string : ")
7+
print(leng(x.split()))
8+

Assignment 38.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Define a function which can generate a dictionary where the keys are numbers
2+
# between 1 and 20 (both included) and the values are square of keys.
3+
# The function should just print the values only
4+
5+
d=dict()
6+
for x in range(1,21):
7+
d[x]=x**2
8+
print(d)

Assignment 39.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write a program to generate and print another tuple whose values are even
2+
# numbers in the given tuple (1,2,3,4,5,6,7,8,9,10)
3+
4+
5+
tu = (1,2,3,4,5,6,7,8,9,10)
6+
print("Before Tuple edit = ", tu)
7+
list1=[]
8+
for i in range(len(tu)):
9+
if(tu[i] % 2 == 0):
10+
print(tu[i], end = " ")
11+
list1.append(tu[i])
12+
print("\nAfter edit the tuple : ",tuple(list1))

Assignment 40.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Write a program which can filter even numbers in a list by using
2+
# filter function. The list is:[1,2,3,4,5,6,7,8,9,10]
3+
def even(n):
4+
if n%2==0:
5+
return n
6+
list1= [1,2,3,4,5,6,7,8,9,10]
7+
lis2 = list(filter(even, list1))
8+
print(lis2)
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+

Assignment 41.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a program which can map() to make a list whose elements
2+
# are square of elements in [1,2,3,4,5,6,7,8,9,10].
3+
def square(n):
4+
return n * n
5+
nums = [1,2,3,4,5,6,7,8,9,10]
6+
result = map(square, nums)
7+
print(list(result))

Assignment 42.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 37. Write a program which can map() and filter() to make a list whose elements
2+
# are square of even number in [1,2,3,4,5,6,7,8,9,10].
3+
4+
li = [1,2,3,4,5,6,7,8,9,10]
5+
eve_num = map(lambda x: x**2, filter(lambda x: x%2==0, li))
6+
print(list(eve_num))

Assignment 43.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write a program to compute 1/2 + 2/3 + 3/4 +...+n/n+1 with a given n input by console (n>0).
2+
3+
4+
def cas(n):
5+
a=1
6+
b=2
7+
c=a/b
8+
for i in range(0,n):
9+
c=c+((a+1)/(b+1))
10+
return c
11+
n=int(input("Enter the number N : "))
12+
print('1/2 + 2/3 + 3/4 +...+',n,'/',n,'+1 : ',cas(n))

Assignment 44.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 39. Write a program to compute:
2+
# a. f(n)=f(n-1)+100 when n>0
3+
# b. and f(0)=1
4+
# c. with a given n input by console (n>0).
5+
6+
def times(n):
7+
if n==0:
8+
return 0
9+
else:
10+
return times(n-1)+100
11+
n=int(input("Enter the number to find f(n)=f(n-1)+100 : "))
12+
if n==0:
13+
print("f (",n,') = f (',n,"- 1) + 100 = 1 ")
14+
else:
15+
print("f (",n,') = f (',n,"- 1) + 100 = ",times(n))
16+
17+
18+
19+
20+
21+

Assignment 45.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Write a program to generate a list with 5 random numbers between 100 and 200 inclusive
2+
3+
import random
4+
list1=[random.randint(100,201) for a in range(0,5)]
5+
print(list1)

assignment 01 odd or even number.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Question
2+
# 1. Print all the odd numbers and even numbers in a given range
3+
4+
start=int(input("Enter the starting value = "))
5+
end=int(input("Enter the ending value = "))
6+
7+
for i in range(start,end):
8+
if ((i%2)==0):
9+
print(f"The {i} is Even Number")
10+
else:
11+
print(f"The {i} is Odd Number")
12+
13+
14+
15+
16+
17+
18+
19+

0 commit comments

Comments
 (0)