Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

PYTHON COMMANDS

Assignment No 5

BY

IMDAD ULLAH

Registration No: 17244

MS COMPUTER SCIENCE

SUBMITTED TO
SIR MUHAMMAD HARIS SHAMS
Dated: 21/12/2021

DEPARTMENT OF COMPUTER SCIENCE


ABASYN UNIVERSITY PESHWAR
KHYBER PAKHTUNKHWA PAKISTAN
1. Write a Python function to find the Max of three numbers.

My_List1=[8,25,200]

print (My_List1)

maximum=(max(My_List1))

print (maximum)

2. Write a Python function to sum all the numbers in a list.

My_List2=[1,2,3,10,12,0,20]

print (My_List2)

Addition=sum(My_List2)

print(Addition)
3. Write a Python function to multiply all the numbers in a list.

import numpy

My_List3=[8,2,3,-1,7,4,5]

print (My_List3)

Product=numpy.prod(My_List3)

print(Product)

4. Write a Python program to reverse a string.

def My_Function(x):

return x[::-1]

My_Text = My_Function("Machine Learning using Python")

print(My_Text)
5. Write a Python function to calculate the factorial(recursive function) of a number (a non-negative
integer). The function accepts the number as an argument.

def factorial(n):

p=1

i=1

while i<=n:

p= p*i

i+=1

return p

factorial(4)

You might also like