️ DEPRECATED GITLAB INSTANCE ️ This GitLab is now read-only for reference. Please use https://gitlab.iauro.co for all new work.

Migration completed on September 17, 2025

Commit 2e205695 authored by MotiramShinde's avatar MotiramShinde

1st python assignment

parent e4d44b3c
def calculator():
while True:
try:
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == '+':
result = num1 + num2
elif op == '-':
result = num1 - num2
elif op == '*':
result = num1 * num2
elif op == '/':
if num2 == 0:
print("Cannot divide by zero.")
continue
result = num1 / num2
else:
print("Invalid operator.")
print(f"Result: {result}")
break
except ValueError:
print("Please enter valid numbers.")
calculator()
import argparse
import os
import json
import csv
def parse_file(path, file_type):
if not os.path.exists(path):
print("File not exist.")
return
try:
if file_type == "text":
with open(path, "r") as f:
print(f.read())
elif file_type == "lines":
with open(path, "r") as f:
for i, line in enumerate(f, 1):
print(f"{i}: {line.strip()}")
elif file_type == "csv":
with open(path, newline='') as f:
reader = csv.reader(f)
for row in reader:
print(row)
elif file_type == "json":
with open(path, "r") as f:
data = json.load(f)
print(json.dumps(data, indent=2))
else:
print("Unsupported file type.")
except Exception as e:
print("Error:", e)
def main():
parser = argparse.ArgumentParser(description="File Parser CLI")
parser.add_argument("filepath", help="Path to file")
parser.add_argument("--type", default="text", choices=["text", "lines", "csv", "json"])
args = parser.parse_args()
parse_file(args.filepath, args.type)
if __name__ == "__main__":
main()
class Student:
def __init__(self, roll_no, name, age):
self.roll_no = roll_no
self.name = name
self.age = age
def display(self):
print(f"Roll No: {self.roll_no}, Name: {self.name}, Age: {self.age}")
students = []
def add_student():
roll_no = input("Enter roll number: ")
name = input("Enter name: ")
age = input("Enter age: ")
student = Student(roll_no, name, age)
students.append(student)
print("Student added successfully!")
def view_students():
if not students:
print("No students to display.")
else:
print("Student List:")
for s in students:
s.display()
def search_student():
roll_no = input("Enter roll number to search: ")
found = False
for s in students:
if s.roll_no == roll_no:
print("Student found:")
s.display()
found = True
break
if not found:
print("Student not found.")
def delete_student():
roll_no = input("Enter roll number to delete: ")
for s in students:
if s.roll_no == roll_no:
students.remove(s)
print("Student deleted.")
return
print("Student not found.")
def main():
while True:
print("\n=== Student Management System ===")
print("1. Add Student")
print("2. View All Students")
print("3. Search Student")
print("4. Delete Student")
print("5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == "1":
add_student()
elif choice == "2":
view_students()
elif choice == "3":
search_student()
elif choice == "4":
delete_student()
elif choice == "5":
break
else:
print("Invalid choice.try again")
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment