[Link] a program to demonstrate different basic data types in python.
Program:
a = 10
print("Integer value:", a)
print("Type:", type(a))
b = 10.5
print("\nFloat value:", b)
print("Type:", type(b))
c = "Hello Python"
print("\nString value:", c)
print("Type:", type(c))
d = True
print("\nBoolean value:", d)
print("Type:", type(d))
e = [1, 2, 3, 4]
print("\nList value:", e)
print("Type:", type(e))
f = (5, 6, 7)
print("\nTuple value:", f)
print("Type:", type(f))
g = {8, 9, 10}
print("\nSet value:", g)
print("Type:", type(g))
h = {"name": "John", "age": 21}
print("\nDictionary value:", h)
print("Type:", type(h))
Output:
[Link] a menu driven program for reading the input from console and to perform different
arithmetic operations on numbers in python.
Program:
while True:
print("\n===== Arithmetic Operations Menu =====")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")
choice = int(input("Enter your choice (1-5): "))
if choice == 5:
print("Exiting program... Thank you!")
break
if choice >= 1 and choice <= 4:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == 1:
print("Result:", num1 + num2)
elif choice == 2:
print("Result:", num1 - num2)
elif choice == 3:
print("Result:", num1 * num2)
elif choice == 4:
if num2 != 0:
print("Result:", num1 / num2)
else:
print("Error! Division by zero is not allowed.")
else:
print("Wrong choice!Please select between 1 and 5.")
Output:
[Link] a Programs using Decision statements and looping statements.
Programs:
1)Check whether a number is Positive, Negative, or Zero.
num = float(input("Enter a number: "))
if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")
Output:
2)
Print even numbers from 1 to N.
n = int(input("Enter limit: "))
for i in range(1, n+1):
if i % 2 == 0:
print(i)
Output: