Professional Documents
Culture Documents
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:
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:
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))
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