You are on page 1of 4

Assignment 3:

Shefali Naik
191103058
TE E&E

2. Define a function that accepts a number and returns whether the number is even or
odd
Source code:
num=int(input("Enter a number to check odd or even: "))
def find_Evenodd(num):

if(num%2==0):
print(num," Is an even")
else:
print(num," is an odd")
find_Evenodd(num);

Output:

3. Define a function that accepts a radius and returns area of a circle


Source code:
pi = 3.14
def circle(r):
return(pi * r * r)

radius = float(input("Enter the radius:"))


area = (circle(radius))
print("area of the circle = ", area)

Output:
4. Write a function in python to read lines from a text file notes.pxt and to find and
display the occurrence of the word “the”

Source code:
file = open("notes.txt", "r")
data = file.read()
occurrence = data.count("the")
print('number of occurrences of the: ', occurrence)

Text file:

Output:

5. Find maximum of three numbers using function


Source code:
num1=int(input("Enter the first number: "));
num2=int(input("Enter the second number: "));
num3=int(input("Enter the Third number: "));
def find_Biggest(): #function definition
if(num1>=num2) and (num1>=num2):
largest=num1
elif(num2>=num1) and (num2>=num3):
largest=num2
else:
largest=num3
print("Largest number is",largest)

Output:
6. Multiply all numbers in a list
Source code:
def multiply_list(numbers):
total = 1
for x in numbers:
total = total * x
return total

print(multiply_list((2, 3, 8, -2)))

Output:

7. Ask the user for a number if it’s even print even or else print odd.
Source Code:
num = int(input("Enter a number: "))
if(num % 2 == 0):
print("num is even".format(num))
else:
print("num is odd".format(num))

num = int(input("Enter a number:"))


flag = num%2
if(flag == 0):
print(num, "is an even number")
elif(flag == 1):
print(num, " is an odd number")
else:
print("Error, Invalid input")

Output
8. Print numbers from 1 to 10
for i in range(1,11):
print(i)

Output:

9. Print numbers between 1000 to 2000 which are divisible by 7 but not a multiple of 5
n1 = [ ]
for x in range(1000, 2500):
if(x % 7 == 0) and (x % 5 == 0):
n1.append(str(x))

print(','.join(n1))

Output

You might also like