Python Assignment
Python Assignment
Python Assignment
Output
a=0
b=1
n=int(input("Enter the No. of terms needed"))
while(n>0):
c=a+b
a=b
b=c
print(c)
n=n-1
Output
3. Write a Program to find a Factorial of a number?
a = int(input("Enter Number"))
b=1
for i in range(1,a+1):
b=b*i
print ("Factorial is",b)
Output
if age>=18:
status="Eligible"
else:
status="Not Eligible"
Output
6. WAP to accept numbers & find out how many numbers are even or odd?
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
Output
Output
8. WAP to allow user to enter 10 numbers and find out their products and sum?
s=0
p=1
c=10
while(c==0):
a=int(input("Enter the Value"))
s=s+a
p=p*a
c=c-1
print("Sum of Numbers are",s)
print("And Product are",p)
Output
9. WAP to accept marks of n number of students for their 3 respective subjects. Calculate average
& Sum of individual Students as well as collectively
Python Functions
10. Write a function which will find out the sum of 2 digit number for a parameter passes to it.
def fun(num):
sum = 0
a=num%10
b=num/10
sum = a+b
return sum
Output
11. Write a function which will accept the Input as age of the person & State of the person and will
return whether he/she is able to vote or not
Output
12. Demonstrate an example with function by showcasing use of default parameter
# 1 keyword argument
student(firstname ='Jason')
# 2 keyword arguments
student(firstname ='Jason', standard ='Seventh')
# 2 keyword arguments
student(lastname ='Gerad', firstname ='Jason')
Output
13. Write a function which will find out sum of even numbers upto the term passed to it.
Output
14. Example of Slide 13
In this example we have created a list of abc and assigned separately values of a, b and c
#!/usr/bin/python
a, b, c = 0, 0, 0; abc = [0,0,0]
def getabc(a,b,c):
a = "Hello"; b = "World"; c = "!"
print 'Inside: a,b,c: ',a,b,c
return
def getlist(abc):
seq = ['Hello','World','!']
for index in range(len(abc)):
abc.pop(0)
abc.extend(seq)
print 'Inside: abc: ',abc
return
x = getabc(a,b,c)
print 'Outside: a,b,c: ',a,b,c
y = getlist(abc)
print 'Outside: abc: ',abc
Output