0% found this document useful (0 votes)
19 views7 pages

1: Python Program To Add 2 Numbers

Computer project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

1: Python Program To Add 2 Numbers

Computer project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1: Python Program To Add 2 Numbers

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

sum = num1 + num2

print("The sum of", num1, "and", num2, "is", sum)

print("Program By Nikhil")
2: Python Program To swap Two Values Without Using Third value and Display New
Value
a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

a, b = b, a

print("After swapping:")

print("First number:", a)

print("Second number:", b)

print("Program By Nikhil")
3: Python Program To make a calculator
while True:

print("Select operation:")

print("1. Add")

print("2. Subtract")

print("3. Multiply")

print("4. Divide")

choice = input("Enter choice (1/2/3/4): ")

if choice in ['1', '2', '3', '4']:

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

if choice == '1':

result = num1 + num2

print(f"{num1} + {num2} = {result}")

elif choice == '2':

result = num1 - num2

print(f"{num1} - {num2} = {result}")

elif choice == '3':

result = num1 * num2

print(f"{num1} * {num2} = {result}")

elif choice == '4':

if num2 == 0:

print("Cannot divide by zero!")

else:

result = num1 / num2

print(f"{num1} / {num2} = {result}")

else:

print("Invalid input. Please enter a valid choice.")

again = input("Do you want to perform another calculation? (yes/no): ")

if again.lower() != 'yes':

print("Exiting the calculator. Program Made by Nikhil")

break
4: Python Program To Check Whether A Character Is Small Or Capital
char = input("Enter a character: ")

if len(char) == 1:

if char.islower():

print("Small letter")

elif char.isupper():

print("Capital letter")

else:

print("Not a letter")

else:

print("Please enter a single character.")

print("Program By Nikhil")
Python program to change one datatype to another:
num_str = "123"
num_int = 456
num_float = 78.90
num_list = [1, 2, 3]
str_to_int = int(num_str)
int_to_float = float(num_int)
float_to_str = str(num_float)
list_to_tuple = tuple(num_list)
tuple_to_list = list(list_to_tuple)
print("String to Integer:", str_to_int)
print("Integer to Float:", int_to_float)
print("Float to String:", float_to_str)
print("List to Tuple:", list_to_tuple)
print("Tuple to List:", tuple_to_list)
Python Program To :
(i):Traverse A List:
my_list = [10, 20, 30, 40, 50]

print("Traversing using a for loop:")

for item in my_list:

print(item)

print(“Code By Nikhil”)

(ii):A 2d List:
my_list = [[10, 20, 30, 40, 50]]

for i in my_list:

for item in i:

print(item)

print("code by Nikhil")

(iii)Python Program To Receive A List From User & Traverse It:

my_list = []

i=0

while True:

a=eval(input("Enter List Element :"))

my_list.append(a)

i=+1

again=input("AGAIN? y/n:")

if again=="n":

break

for item in my_list:

print(item)

print("Code By Nikhil")
7: Python Program To receive string from user and traverse it:

user_input = input("Please enter a string: ")


for i in user_input:
print(i)
print('program by nikhil')

You might also like