Advertisement
GamerBhai02

Assignment 1

Mar 20th, 2025 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | Source Code | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. # #Experiment 1
  5.  
  6. # In[30]:
  7.  
  8.  
  9. import os
  10. with open('std_records.txt','w') as file:
  11.     file.write('Student Name,Roll Number,Student Marks\n')
  12.     file.write('John,1001,98\n')
  13.     file.write('Ben,1002,84\n')
  14.     file.write('Tom,1003,91\n')
  15.     file.write('Adam,1004,76\n')
  16.     file.write('Tim,1005,89')
  17.     print("Records Inserted Successfully")
  18.  
  19.  
  20. # In[31]:
  21.  
  22.  
  23. if os.path.exists('std_records.txt'):
  24.     with open('std_records.txt','r') as file:
  25.         print(file.read())
  26. else:
  27.     print("Student Records Doesnt Exist")
  28.  
  29.  
  30. # In[32]:
  31.  
  32.  
  33. if os.path.exists('std_records.txt'):
  34.     roll_number = input("Enter Student Roll Number:")
  35.     with open('std_records.txt', 'r') as file:
  36.         header = file.readline()
  37.         found = False
  38.         for line in file:
  39.             if roll_number in line:
  40.                 print(f"Record Found:\n{header}{line.strip()}")
  41.                 found = True
  42.                 break
  43.         if not found:
  44.             print("Record not found.")
  45. else:
  46.     print("Student Records Doesnt Exist")
  47.  
  48.  
  49. # In[33]:
  50.  
  51.  
  52. with open('C:\\Users\\Student\\Pictures\\sampleimg.jpg','rb') as img:
  53.     imagedata = img.read()
  54.  
  55.  
  56. # In[34]:
  57.  
  58.  
  59. from PIL import Image
  60. import matplotlib.pyplot as plt
  61. with open('output_image.jpg','wb') as img:
  62.     image = img.write(imagedata)
  63. image = Image.open('output_image.jpg')
  64. plt.imshow(image)
  65. plt.axis("off")
  66. plt.show()
  67.  
  68.  
  69. # In[35]:
  70.  
  71.  
  72. import zipfile
  73. with zipfile.ZipFile("student_zipped.zip",'w') as zipf:
  74.     zipf.write('std_records.txt')
  75.     zipf.write('student_details.bin')
  76.     print("Files Zipped Successfully")
  77.  
  78.  
  79. # In[36]:
  80.  
  81.  
  82. with zipfile.ZipFile("student_zipped.zip",'r') as zipf:
  83.     zipf.extractall("Student Details")
  84.     print("Files Unzipped Successfully")
  85.  
  86.  
Tags: Ass 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement