Monday, 24 June 2019

Assessment 8

1.    Find out whether the given no is even or odd
a=int(input("enter any value"))
if a%2==0:
    print(a," is even number")
else:
    print(a," is odd number")
"""
output
enter any value4
4  is even number
>>> 
enter any value11
11  is odd number
>>>

2.    Wap to display simple calculator: For example if my input is 1, it should calculate addition, if my input is 2, it should calculate subtraction, if my input is 3, it should multiply, if my input is 3, I should get division result, if my input is other than 1 to 4 then it should display message “ invalid number”
Ans:
print("1. Addition")
print("2. sub")
print("3. Mul")
print("4. Division")
print("5. Invalid no")
n=int(input("enter 1 to 4: "))
a=int(input("enter first no: "))
b=int(input("enter 2nd no: "))
if n==1:
    c=a+b
    print("addition =",c)
elif n==2:
    c=a-b
    print("sub=",c)
elif n==3:
    c=a*b
    print("mul=",c)
elif n==4:
    c=a/b
    print("division=:",c)
else:
    print("invalid no")


3.    find the Largest of 3 nos
a=int(input("Enter 1st no"))
b=int(input("enter 2nd no"))
c=int(input("enter 3rd no"))

#Logic
if a>b and a>c:
            print("Big no is a=",a)
elif b>c:
            print("Big no is b=",b)
else:
            print("Big no is c=",c)
"""
Note1:
Enter 1st no 10
enter 2nd no 20

enter 3rd no 30

Note2:
Enter 1st no 40
enter 2nd no 20
enter 3rd no 5
Big no is a= 40
>>>


4.    Find the factorial of a given number using for loop:
prod=1
n=int(input("enter any no"))
for i in range(1,n+1):
    prod=prod*i
print(prod)

"""output:
enter any no3
5.    Generate the fibonacci series upto 8
n=int(input("enter any no"))
a=0
b=1
print("Fibonacci series are ")
print(a)
print(b)
i=1
while i!=n-2:
    c=a+b
    print(c)
    a=b
    b=c
    i=i+1
"""output:
enter any no6
Fibonacci series are
0
1
1
2
3
"""
6.    Find out the whether the given no is perfect no or not?
n=int(input("enter any no"))
sum=0
for i in range(1,n):
    if n%i==0:
        sum=sum+i
if n==sum:
    print("it is perfect no")
else:
    print("it is not perfect no")
"""output:
enter any no6
it is perfect no
>>> """

7.    Display reverse of order from 10 to 1:
>>> for a in range(10,0,-1):
            print(a)
output:10 9 8 7 6 5 4 3 2 1
>>>

8.    Calculate the Sum of a list
sum of a list numbers using for loop:
a=[10,20,30]
sum=0
print(a)
for i in a:
    sum=sum+i
print(sum)

"""output:
[10, 20, 30]
60

9.    Write a program to generate the pyramid share (Triangle shape)
n=int(input("enter no of rows "))
for i in range(1,n+1):
    print(" "*(n-i),end="")
    print("* "*i)
"""output:
enter no of rows 3
  *
 * *
* * *

10. Display the output in the following format:
1 0
1 1
Ans: for i in range(1,2):
    for j in range(2):

        print(i,j)

Next Topic: The else suite
Assessments

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...