0% found this document useful (0 votes)
23 views3 pages

Function Programs

The document contains a series of Python function definitions that perform various tasks, such as finding numbers divisible by 7 but not by 5, counting letters and digits in a string, concatenating two strings, generating squares of numbers, and printing halves of a tuple. Each function is defined with specific input parameters and includes print statements to display the results. The functions demonstrate basic programming concepts such as loops, conditionals, and string manipulation.

Uploaded by

Jai Sharma
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)
23 views3 pages

Function Programs

The document contains a series of Python function definitions that perform various tasks, such as finding numbers divisible by 7 but not by 5, counting letters and digits in a string, concatenating two strings, generating squares of numbers, and printing halves of a tuple. Each function is defined with specific input parameters and includes print statements to display the results. The functions demonstrate basic programming concepts such as loops, conditionals, and string manipulation.

Uploaded by

Jai Sharma
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/ 3

Q.

4 Define a function which will find all such numbers which are divisible by 7 but are not a

multiple of 5,between 1000 and 3000 (both included)

def fun():

nl=[]

for x in range(1000, 3001):

if (x%7==0) and (x%5!=0):

nl.append(str(x))

print (','.join(nl))

fun()

Q.5 Define the same function of question no 4 where starting and ending number is passedas argument

def fun(start,end):

nl=[]

for x in range(start,end):

if (x%7==0) and (x%5!=0):

nl.append(str(x))

print (','.join(nl))

x=int(input("enter x value"))

y=int(input("enter y value"))

fun(x,y)

Q.6 Define a function that accepts a sentence and calculate the number of letters and digits

s = input("Input a string")

d=l=0

for c in s:

if c.isdigit():

d=d+1

elif c.isalpha():

l=l+1
else:

pass

print("Letters", l)

print("Digits", d)

Q.7 Define a function that accepts a sentence and calculate the number of upper case

letters and lower case letters

s = input("Input a string")

d=l=0

for c in s:

if c.isupper():

d=d+1

elif c.islower():

l=l+1

else:

pass

print("Upper case Letters", l)

print("Lower case letters", d)

Q.8 Define a function that can accept two strings as input and concatenate them and then print it in console.

def concatenet(str1,str2):

z=''

z=x+y

print(z)

x=input("enter string1")

y=input("enter string2")

concatenet(x,y)
Q.9 Define a function which can generate and print a list where the values are square of

numbers between 1 and 20 (both included).

def printValues():
l = list()
for i in range(1,21):
l.append(i**2)
print(l)

printValues()

Q.10 With a given tuple (1,2,3,4,5,6,7,8,9,10), define a function to print the first half values

in one line and the last half values in one line.

Def tup():

tp=(1,2,3,4,5,6,7,8,9,10)

tp1=tp[:5]

tp2=tp[5:]

print(tp1)

print(tp2)

tup()

You might also like