Assignment No 1

You might also like

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

Assignment-1

1. A simple program that displays “Hello, World!”. It is often used to


illustrate the syntax of the language.
Ans- print("Hello, World!")

2. Give the example of interactive mode and script mode.


Ans-

3. Write a program on types of variable and also which type of


variable is immutable or mutable
Ans –
list=[12,14,67,90] - mutable
tuple=(1,"Pratiksha",77) - immutable
a=9 - Integer - immutable
str="Pratiksha" - immutable
0==1 -Boolean- immutable
F=19.0 - Float- immutable

4. Write a program on operators with priority and associativity.


Ans-
expression = 100 + 200 / 10 - 3 * 10
print(expression )
5. Write a simple program for using comment.
Ans-
#Print "Hello World!" in python
print("Hello, World!")

6. A Simple program In Python Program to Add Two Numbers.


Accept number from user.
Ans-
num1=int(input("Enter a number: "))
num2=int(input("Enter a number: "))
print("Addition of two number: ",num1+num2)

7. Write A Program in python language to Find the Square Root.


Ans-
import math
num1=int(input("Enter a number: "))
print("Squareroot of number: ",math.sqrt(num1))

8. Write A Python Program to Calculate the Area of a Triangle.


Ans-
h=int(input("Enter height of Triangle: "))
b=int(input("Enter base of Triangle: "))
Area=(h*b)/2
print("Area of Triangle: ",Area)
9. Write A Python Program to Solve Quadratic Equation.
Ans-
import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))

d = (b**2) - (4*a*c)

sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are',sol1,'and',sol2)

10. Write A Python program to check if a number is positive,


negative or zero.
Ans-
n=int(input("Enter a Number: "))
if n==0:
print("Zero")
elif n>0:
print("Positive")
else:
print("Negative")

11.Write A Python Program to Check if a Number is Odd or Even.


Ans-
n=int(input("Enter a Number: "))
if n%2==0:
print("Number is Even")
else:
print("Number is Odd")

12. Write A Python Program to Check Leap Year.


Ans-
year=int(input("Enter year to be checked:"))
if(year%4==0 and year%100!=0 or year%400==0):
print("The year is a leap year!")
else:
print("The year isn't a leap year!")

13. Write A Python Program to Find the Largest Among Three


Numbers.
Ans-
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is", largest)

14.Write A Python Program to Check Prime Number.


Ans-
num =int(input("Enter a number: "))
if num > 1:
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

15. Write a program on complex number.


Ans-
z = complex(5, 7)
print("Output:", z)

You might also like