0% found this document useful (0 votes)
4 views8 pages

Python Assignment 1

The document contains Python programs demonstrating basic data types, arithmetic operations, decision statements, and looping statements. It includes examples for integers, floats, strings, booleans, lists, tuples, sets, and dictionaries, as well as a menu-driven program for arithmetic operations. Additionally, it features programs to check if a number is positive, negative, or zero, and to print even numbers from 1 to a specified limit.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Python Assignment 1

The document contains Python programs demonstrating basic data types, arithmetic operations, decision statements, and looping statements. It includes examples for integers, floats, strings, booleans, lists, tuples, sets, and dictionaries, as well as a menu-driven program for arithmetic operations. Additionally, it features programs to check if a number is positive, negative, or zero, and to print even numbers from 1 to a specified limit.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[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:

You might also like