0% found this document useful (0 votes)
18 views9 pages

Assignment 1

random

Uploaded by

Ankit Kapadnis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
18 views9 pages

Assignment 1

random

Uploaded by

Ankit Kapadnis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

Write a python program for basic

calculator
# add two numbers

def add(num1, num2):

return num1 + num2

# subtract two numbers

def subtract(num1, num2):

return num1 - num2

# multiply two numbers

def multiply(num1, num2):

return num1 * num2

# divide two numbers

def divide(num1, num2):

return num1 / num2

print("Please select operation -\n" \

"1. Add\n" \

"2. Subtract\n" \
"3. Multiply\n" \

"4. Divide\n")

# Take input from the user

select = int(input("Select operations from 1, 2, 3, 4 :"))

number_1 = int(input("Enter first number: "))

number_2 = int(input("Enter second number: "))

if select == 1:

print(number_1, "+", number_2, "=",

add(number_1, number_2))

elif select == 2:

print(number_1, "-", number_2, "=",

subtract(number_1, number_2))

elif select == 3:

print(number_1, "*", number_2, "=",

multiply(number_1, number_2))
elif select == 4:

print(number_1, "/", number_2, "=",

divide(number_1, number_2))

else:

print("Invalid input")

Please select operation -

1. Add

2. Subtract

3. Multiply

4. Divide

OUTPUT
Write a program that takes users first name
last name and age and print them after
concatenation
firstname = input("enter your First Name : ")

lastname = input("enter your Last Name : ")

age = input("enter your age :")

str_a = firstname + lastname + age

print (str_a)

OUTPUT
Write a program to print all bitwise operators

# Python program to show

# bitwise operators

a = 10

b=4

# Print bitwise AND operation

print("a & b =", a & b)

# Print bitwise OR operation

print("a | b =", a | b)

# Print bitwise NOT operation

print("~a =", ~a)

# print bitwise XOR operation

print("a ^ b =", a ^ b)

# print bitwise right shift operator

print("a >> 1 =", a >> 1)


print("b >> 1 =", b >> 1)

# print bitwise left shift operator

print("a << 1 =", a << 1)

print("b << 1 =", b << 1)

OUTPUT
Write a program in python using all logical
operators
# Python program to demonstrate

# logical and operator

a = 10

b = 12

c=0

if a > 0 and b > 0:

print("The numbers are greater than 0")

if a > 0 and b > 0 and c > 0:

print("The numbers are greater than 0")

else:

print("Atleast one number is not greater than 0")

# logical or operator

if a > 0 or b > 0:
print("Either of the number is greater than 0")

else:

print("No number is greater than 0")

if b > 0 or c > 0:

print("Either of the number is greater than 0")

else:

print("No number is greater than 0")

# logical not operator

if not a:

print("Boolean value of a is True")

if not (a%3 == 0 or a%5 == 0):

print("10 is not divisible by either 3 or 5")

else:

print("10 is divisible by either 3 or 5")


OUTPUT

You might also like